Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does DOM order determine the order of form parameters posted?

If I have a form like this:

<form>
  <input name="param[]" />
  <input name="param[]" />
  <input name="param[]" />
</form>

Can I expect to receive these parameters in the same order when the form is submitted?

I've noticed that Chrome, Rails, and Webrat preserve the order of the parameters, but that may be caused by implementation details rather than adherence to a standard.

like image 738
nicholaides Avatar asked Jul 21 '10 14:07

nicholaides


1 Answers

This is the standard. I find that the W3C specification is very useful and readable.

application/x-www-form-urlencoded...

The control names/values are listed in the order they appear in the document.

multipart/form-data...

The parts are sent to the processing agent in the same order the corresponding controls appear in the document stream.

I have yet to encounter a browser that doesn't follow this convention, so I'd say you're pretty safe to use it.

That being said, my semantic bone is a bit uncomfortable with relying on this convention. If ordering is crucial, I would instead use:

<form>
  <input name="param[0]" />
  <input name="param[1]" />
  <input name="param[2]" />
</form>
like image 53
Steven Avatar answered Nov 15 '22 12:11

Steven