views:

31

answers:

3

Is there any way to reorder or manipulate a set of inputs before posting to a script for processing? I'm able to reorder the elements in the DOM no problem, but getting this to happen after the user presses the submit button and before the browser makes the POST is a bit tricky. I'm using the ajaxForm plugin in jQuery. There is a beforeSubmit callback, but this doesn't seem to allow me to reorded the inputs.

+2  A: 

As far as I know, the order the inputs are sent to the server is not guaranteed by the spec (correct me if I'm wrong). So what's the point of reordering them? I don't see why this is useful.

rmeador
I understand that there is no guaranteed order, but in all of my testing, I have never seen the POST variables come in a different order than what was expected, ie. left to right.
Jason
+1  A: 

There is no good reason to want to do this.

hobodave
+1  A: 
$('#form').ajaxForm({ beforeSerialize: orderInputsFunction });

This works. With the jQuery Form Plugin, you can manipulate the form using a call back function with the beforeSerialize option.

In my unfortunate case, I'm working with a PHP script that assumes certain post variables will be in a particular order.

Jason