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

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

html - 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.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...