Search code examples
phpjavascriptjqueryjsonserializer

reverse serialize() -jquery


I sent my data (json) for an ajax request with this code;

var formdata = $("#customForm").serialize();

            type: "post",
            dataType: "json",
            data: formdata,

In the php file, there is possible reverse the serialize?

or i need to make something like that: $pass = $_POST['pass']; for all fields?

thanks


Solution

  • it sounds like you are headed in the right direction with your "or" statement. The data should be available in the $_POST array without needing to "deserialize" anything.

    EDIT

    Try to name your input fields so that they all come into the post variable as an array:

    <input name="myformdata[first_name]" id="first_name" />
    <input name="myformdata[last_name]" id="last_name" />
    

    Then in the post array you can access all the form data like:

    <?php $form_data_array = $_POST['myformdata']; ?>