Fork me on GitHub

jQuery-form-serializer

Serialize forms to JSON objects in a friendly way.

Download .zip Download .tar.gz View on GitHub

Example

<script src="path/to/jQuery.js"></script>
<script src="path/to/jQuery-serializer.js"></script>
<script>
    $("form")
        .serializer();
        .on("serializer:data", function (e, formData) {
            alert(JSON.stringify(formData));
        })
        ;
</script>

When passing the data-convert-to attribute, the value will be converted in that data type. Currently the following are supported:

  • string
  • number
  • boolean

data-field is mandatory for the fields which you want to be listed in the JSON object.

Inspect the HTML with the browser developer tools so you can see what's behind this pretty form.

Enter your first name.
Enter your first name.
How old are you? If you provide 0, the age field will be deleted.
How old are you? If you provide 0, the age field will be deleted.
I'm readonly content and my value is taken with data-value="html".
Check out the documentation on GitHub.