Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
602 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...