Serialize multiple forms together?

Can you serialize multiple forms into one so that only one post or ajax request is made? I have searched around and it is all for submiting each form separently via post/ajax.


Solution 1:

If you run $('form').serialize() on a page with multiple forms, it will correctly serialize all the forms into one string.

To include only certain forms, use $('#form1, #form2').serialize()

Solution 2:

When you use the jQuery serialize() function, it simply turns your form into a string in the format a=1&b=2&c=3. So you can certainly apply this function to two forms and concatenate the result, with an & between them, and use the result in your ajax call. You'd want some checks to make sure neither string is empty when you do the concatenation.