I am using a fairly standard JSON.stringify function, that gets passed across to a jQuery function that serializes this object.
However I'd like to make an modification to allow an array of inputs to be posted. Much like how the current solution handles a collection of checkboxes.
E.g.
<fieldset name="clothes">
<input type="number" name="coat" />
<input type="number" name="jacket" />
<input type="number" name="jeans" />
<input type="number" name="(guid)" />
</fieldset>
These are all items of clothing so I'd like to form them into something like:
{ "Clothes": { "coat" : 2 , "jacket" : 10 , "jeans" : 1 } }
In the above, the function needs to support an additional level of grouping. My first thoughts on this are to add a name to the fieldset. This seems logical to me. However as per HTML spec's the fieldset element isn't part of the form submission, so there would be some that would say adding a NAME to this element for this purpose, violates the specification. However, as the specification supports adding a 'name' attribute, I think this is perfectly valid.
In the context of the entire form, I'm looking for something that supports:
<fieldset>
<input type="text" name="Name" />
<input type="text" name="Email" />
</fieldset>
<fieldset name="clothes">
<input type="number" name="coat" />
<input type="number" name="jacket" />
<input type="number" name="jeans" />
<input type="number" name="(guid)" />
</fieldset>
Giving...
{ "Name" : "John" , Email : "x@y.com" , "Clothes": { "coat" : 2 , "jacket" : 10 , "jeans" : 1 } }
I've posted a simplified version of my current code on JSFiddle - http://jsfiddle.net/DR3EA/1/