Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will data order in post form be the same to it in web form?

Tags:

http

post

php

Assuming there are 5 inputs in web form

<input name='the_same[]' value='different' />
<input name='the_same[]' value='different' />
<input name='the_same[]' value='different' />
<input name='the_same[]' value='different' />
<input name='the_same[]' value='different' />

When server side receive the post data, i use a foreach to accept data, say

$the_same = new array();
foreach($_POST['the_same'] as $data)
    $the_same[] = $data;

Will the order of data saved in server side be the same to it in web form? and cross browsers, it could be a criteria all browsers follow.

like image 343
Edward Avatar asked Apr 02 '10 09:04

Edward


2 Answers

Well, the W3C recommendation on HTML forms does say:

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

Still, I'd consider it a bit risky to have your app depend critically on that detail.

like image 67
Michael Borgwardt Avatar answered Oct 06 '22 01:10

Michael Borgwardt


PHP already handles converting POSTed/GETed variables into arrays when you put [] after the name. Do that instead of getting it wrong yourself.

like image 28
Ignacio Vazquez-Abrams Avatar answered Oct 06 '22 00:10

Ignacio Vazquez-Abrams