Awarious OfficePortal - HRMS Application

PHP deserialize form data submitted by jquery ajax post serialized

0 votes
asked Aug 3, 2014 in Php by Ajay

I am trying to implement form submit using jquery ajax post. As per the information given jQuery library documentation, I have serialized the form data before I submit the form to my php url.

<form id="form1" method="POST" action="phpurl">
    <div class="input-group">
        <span class="input-group-addon">Title</span>
            <input type="text" name="title" class="form-control" data-validation="required" data-validation-error-msg="Title required">

    <div class="input-group">
        <span class="input-group-addon">Description</span>
            <input type="text" name="desc" class="form-control" data-validation="required" data-validation-error-msg="Description required">
    <input name="submitform1" value="Save" type="submit" class="qa-form-tall-button qa-form-tall-button-save">

jQuery("form1" ).on( "submit", function( event ) {
    var $form = jQuery('#form1'), url = $form.attr('action').val();
            {formdata: form.serialize()},
        //more code

But in php server side code, I am not able to access the data directly from $POST. All I am looking for is, how to read data from $POST like

$title = $_POST['title'];
$desc = $_POST['desc'];

1 Answer

+1 vote
answered Aug 3, 2014 by Aadhira (1,215 points)
selected Aug 3, 2014 by administrator
Best answer

I have faced the same issue and finally figured out the solution.
When a form data is submitted using serialized, the data will be sent like query string with key value pair. So, in your example, if you read the value of $_POST['formdata'], it will have the serialized string. So, use php parse_str method, that will convert your string to array. After that, you can read value of your form field from that array.

parse_str($_POST['formdata'], $formdata);//This will convert the string to array
$title = $formdata['title'];
$desc = $formdata['desc'];
commented Sep 20, 2014 by anonymous
very good it's amazing. it's solved my problem
commented Sep 14, 2015 by kamlesh
Yes it solved my problem too ! thanks
commented Feb 9, 2016 by Bibitybobityboo

Thanks for the tip!

commented Feb 27, 2017 by anonymous
thankew shooooooooo much work for meee
commented May 17, 2017 by anonymous
Thanks for the tip! ttt

Your answer


Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2019