formRepeat not working with PHP

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 .

Thank you,
Will check right away.

Hi,
Insert works but Update is not. I get the following error:

    "code": 0,
    "file": "/var/www/html/dmxConnectLib/modules/dbupdater.php",
    "line": 288,
    "message": "Undefined property: stdClass::$returning",
    "trace": "#0 /var/www/html/dmxConnectLib/modules/dbupdater.php(288): exception_error_handler(2, 'Undefined prope...', '/var/www/html/d...', 288)\n#1 /var/www/html/dmxConnectLib/lib/App.php(197): modules\\dbupdater->update(Object(stdClass), 'update', Array)\n#2 /var/www/html/dmxConnectLib/lib/App.php(137): lib\\App->execSteps(Object(stdClass))\n#3 /var/www/html/dmxConnectLib/lib/App.php(126): lib\\App->exec(Object(stdClass), false)\n#4 /var/www/html/dmxConnectLib/lib/App.php(104): lib\\App->exec(Object(stdClass))\n#5 /var/www/html/dmxConnect/api/updCustomer.php(8): lib\\App->define(Object(stdClass))\n#6 {main}"
}

Sorry, messed up, this is what im getting now:

{
    "code": 0,
    "file": "/var/www/html/dmxConnectLib/modules/dbupdater.php",
    "line": 317,
    "message": "Array to string conversion",
    "trace": "#0 [internal function]: exception_error_handler(2, 'Array to string...', '/var/www/html/d...', 317)\n#1 /var/www/html/dmxConnectLib/modules/dbupdater.php(317): PDOStatement->execute(Array)\n#2 /var/www/html/dmxConnectLib/lib/App.php(197): modules\\dbupdater->update(Object(stdClass), 'update', 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/updCustomer.php(8): lib\\App->define(Object(stdClass))\n#7 {main}"
}

Here a new update.

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

Thank you Patrick,

Looks like it’s working now.

Fixed in Wappler 5.0.3

This topic was automatically closed after 32 hours. New replies are no longer allowed.