Finding jquery plugin to serialize form to object

I'm looking for a jQuery function or plugin that serializes form input to an object using the deep serialization naming convention supported by param () in jQuery 1.4:

<form>
  <input name="a[b]" value="1"/>
  <input name="a[c]" value="2"/>
  <input name="d[]" value="3"/>
  <input name="d[]" value="4"/>
  <input name="d[2][e]" value="5"/>
</form>

$('form').serializeObject(); // { a: { b:"1",c:"2" }, d: ["3","4",{ e:"5" }] }

      

The Prototype Form.serialize method can do just that. What's the jQuery equivalent? I found this plugin , but it doesn't follow this naming convention.

+2


a source to share


4 answers


Since there didn't seem to be any existing libraries that achieved what I was looking for, I kneaded bits from several existing libraries that did similar things:

  • JQuery.deparam function from jQuery BBQ
  • JQuery.serializeObject function mentioned in the question.


Both are Ben Alman . Thanks Ben!

Result: http://gist.github.com/405448

+3


a source


try using jquery form plugin. I haven't tested it, but I think it will fix your problem.



http://jquery.malsup.com/form/

0


a source


You don't need to connect.

$ ('form'). submit (function () {notifications ($ (this) .serializeArray ()); return false;});

look at http://api.jquery.com/serializeArray/

0


a source


Possibly late, but there the jQuery plugin does what you need.

http://v3.javascriptmvc.com/index.html#&who=jQuery.fn.formParams

0


a source







All Articles