Deserializing Form using this pattern name="object[property]"

Sep 7, 2011 at 11:57 PM

I have been looking for a way to mimic PHP in the fact that everything is an associative array.  The trick is to set up your form names to look like an associative array and everything is gravy.  I can't change some of the classes I'm using to add the Json property info to the class and properties.

Here is what i have so far..

<input type="text" name="Organization[Name]" />

<input type="text" name="Organization[Phone]" />

and so on.

I then iterate over the form and add everything to an object.

var vals = {};
$('form input').each(function(){if( vals[] = $(this).val(); });
//get data ready for controller
var dataToController = encodeUriComponent(JSON.stringify(vals));



The problem is when it gets to the controller I don't know how to get it into my objects..

I'm trying to set the form up so that it will work with PHP really easily because we may start using PHP and I want to change as little as possible...


Any suggestions on how to blow the associative array up into objects??