formRepeat not working with PHP

Wappler Version : 5.0.2
Operating System : MacOS
Server Model: PHP 7.3
Database Type: MariaDB
Hosting Type: Docker/Webhosting company

Expected behavior

What do you think should happen?

Following this Inserting Data in Main and Sub Table using App Connect Form Repeat should work on PHP. With Node its working perfect.

Actual behavior

What actually happens?

I get this error when form is submitted.
{ "code": 0, "file": "/var/www/html/dmxConnectLib/modules/dbupdater.php", "line": 62, "message": "Call to undefined function modules\\str_contains()", "trace": "#0 /var/www/html/dmxConnectLib/lib/App.php(197): modules\\dbupdater-insert(Object(stdClass), 'insert', Array)\n#1 /var/www/html/dmxConnectLib/lib/App.php(137): lib\\App-execSteps(Object(stdClass))\n#2 /var/www/html/dmxConnectLib/lib/App.php(126): lib\\App-exec(Object(stdClass), false)\n#3 /var/www/html/dmxConnectLib/lib/App.php(104): lib\\App-exec(Object(stdClass))\n#4 /var/www/html/dmxConnect/api/insertCustomer.php(8): lib\\App-define(Object(stdClass))\n#5 {main}" }

How to reproduce

  • Detail a step by step guide to reproduce the issue
  • A screenshot or short video indicating the problem
  • A copy of your code would help. Include: JS, HTML.
  • Test your steps on a clean page to see if you still have an issue

Follow this guide:
Following this Inserting Data in Main and Sub Table using App Connect Form Repeat

str_contains() function seems to only be available for PHP 8 and newer and you are using PHP 7.3
https://www.php.net/manual/en/function.str-contains.php

You can update your PHP version to 8 or newer, so that you can use this. Not sure if this can be improved to support older PHP versions, @patrick will check this.

Thank you Teodor!

Have a good summer vacation! Please go crazy on the beer :beers:!!!

1 Like

Now I get the following:
{ "code": 0, "file": "/var/www/html/dmxConnectLib/modules/dbupdater.php", "line": 131, "message": "Array to string conversion", "trace": "#0 [internal function]: exception_error_handler(2, 'Array to string...', '/var/www/html/d...', 131)\n#1 /var/www/html/dmxConnectLib/modules/dbupdater.php(131): PDOStatement->execute(Array)\n#2 /var/www/html/dmxConnectLib/lib/App.php(197): modules\\dbupdater->insert(Object(stdClass), 'insert', Array)\n#3 /var/www/html/dmxConnectLib/lib/App.php(137): lib\\App->execSteps(Object(stdClass))\n#4 /var/www/html/dmxConnectLib/lib/App.php(126): lib\\App->exec(Object(stdClass), false)\n#5 /var/www/html/dmxConnectLib/lib/App.php(104): lib\\App->exec(Object(stdClass))\n#6 /var/www/html/dmxConnect/api/insertCustomer.php(8): lib\\App->define(Object(stdClass))\n#7 {main}" }

I assume that comes from a server action (API) Perhaps we could see the API action to see if anything is wrong with your configuration. Looks like the issue relates to a database insert?

Its exactly as in the tutorial. It’s working when i do it in Node.

I reported the bug with a proposed change.

Hi,
It worked with your code. Probably the same error with update function. Would be great if this could be fixed, its a BIG showstopper for me. How is it possible a major flaw like this is not fixed when software goes from beta to production?

Seems that a function is used that is not supported by PHP 7.3, since we still support PHP 7 this should not happen.

I’ve replaced the function with code that is supported with PHP 7, please test the following update.

dbupdater.zip (2.7 KB) Unzip in dmxConnectLib/modules.

Hi Patrick,
I changed to PHP 8 and it still happens.
Will try your file immediately

No, still the same error.

{ "code": 0, "file": "/var/www/html/dmxConnectLib/modules/dbupdater.php", "line": 131, "message": "Array to string conversion", "trace": "#0 [internal function]: exception_error_handler(2, 'Array to string...', '/var/www/html/d...', 131)\n#1 /var/www/html/dmxConnectLib/modules/dbupdater.php(131): PDOStatement->execute(Array)\n#2 /var/www/html/dmxConnectLib/lib/App.php(197): modules\\dbupdater->insert(Object(stdClass), 'insert', Array)\n#3 /var/www/html/dmxConnectLib/lib/App.php(137): lib\\App->execSteps(Object(stdClass))\n#4 /var/www/html/dmxConnectLib/lib/App.php(126): lib\\App->exec(Object(stdClass), false)\n#5 /var/www/html/dmxConnectLib/lib/App.php(104): lib\\App->exec(Object(stdClass))\n#6 /var/www/html/dmxConnect/api/insertCustomer.php(8): lib\\App->define(Object(stdClass))\n#7 {main}" }

And to be clear, I’m using PHP 8.

Oh sorry, didn’t notice there was an other error in the comment. The fix is for the initial error with the str_contains that didn’t work in PHP 7.3. Will check the second error.

It seems that @Quy has probably a fix for this. Can you give me the json that Wappler generated in the server action file. I checked the fix from @Quy and compared the PHP code with the code used in NodeJS and ASP. It seems that NodeJS and ASP do exactly the same as the PHP code, so it is possible that those are also wrong or that the action file doesn’t generate the options correctly.

Sure, is it this you want?

I have tried in Node and it’s working.

require('../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
  "meta": {
    "options": {
      "linkedFile": "/subtable_insert.php",
      "linkedForm": "insCustomer"
    },
    "$_POST": [
      {
        "type": "text",
        "fieldName": "customerName",
        "name": "customerName"
      },
      {
        "type": "array",
        "name": "formRepeat1",
        "sub": [
          {
            "type": "text",
            "fieldName": "formRepeat1[{{$index}}][contactName]",
            "name": "contactName"
          },
          {
            "type": "text",
            "fieldName": "formRepeat1[{{$index}}][contactPhone]",
            "name": "contactPhone"
          }
        ]
      }
    ]
  },
  "exec": {
    "steps": {
      "name": "insert",
      "module": "dbupdater",
      "action": "insert",
      "options": {
        "connection": "db",
        "sql": {
          "type": "insert",
          "values": [
            {
              "table": "customers",
              "column": "customerName",
              "type": "text",
              "value": "{{$_POST.customerName}}"
            }
          ],
          "table": "customers",
          "sub": {
            "contacts": {
              "type": "insert",
              "table": "customer_contacts",
              "key": "customer_id",
              "values": [
                {
                  "table": "customer_contacts",
                  "column": "contactName",
                  "type": "text"
                },
                {
                  "table": "customer_contacts",
                  "column": "contactPhone",
                  "type": "text"
                }
              ],
              "value": "{{$_POST.formRepeat1}}"
            }
          },
          "returning": "id",
          "query": "INSERT INTO customers\n(customerName) VALUES (:P1 /* {{$_POST.customerName}} */)",
          "params": [
            {
              "name": ":P1",
              "type": "expression",
              "value": "{{$_POST.customerName}}"
            }
          ]
        }
      },
      "meta": [
        {
          "name": "identity",
          "type": "text"
        },
        {
          "name": "affected",
          "type": "number"
        }
      ]
    }
  }
}
JSON
);
?>```

It seems that the specs did change, I see in the NodeJS code that the values array may only contain a single value or it will throw an error, the PHP code did’t have that extra check. Not sure when it was changed, but seems that none of the server models support multiple values this way and should be updated. This will need some extra research, need to check what are all the options/values that are being accepted.

Ok.
What does it mean? Do I need to find another solution than using subtables insert/update?

It means I need a bit more time to figure out why it goes wrong and it seems that not only PHP is affected by this bug but also NodeJS and ASP. I hope to have an update for testing later today or tomorrow.

ok,
great, then I will hold off until then.
Thank you very much :slight_smile:

Here a new update.

dbupdater.zip (2.7 KB) Unzip in dmxConnectLib/modules .