Skip to content
Advertisement

jQuery/Php Error Illegal string offset from unserialized post data

I’m posting a jquery serialize data posting from modal/pop up div tag with name attribute such as formdata[1]field_x

JavaScript

The Fetch/XHR capture the serialized posted data, which indicate the posting is correct. The same result return with print_r($_POST["formdata"] ); .

formdata%5B1%5Dpayref_autonum=Yes&formdata%5B1%5Dpayref_prefix=P2022&formdata%5B1%5Dpayref_suffix=&formdata%5B1%5Dpayref_pad=4&formdata%5B1%5Dpayref_next=876&formdata%5B1%5Dpayref_sample=

The data are getting un-serialized parse_str($_POST["formdata"], $formdata );. However $formdata return an empty array.

JavaScript

Advertisement

Answer

The issue is your form fields name attribute is not an array,(which you are thinking is an array, but has a syntax error).To fix this do like below:

change names like this: formdata[1][payref_autonum] and so on for others.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement