#27631 [NEW]: dynamically generated form elements using name=foo[] submitted out of order

2004-03-17 Thread phpclass at oneroad dot com
From: phpclass at oneroad dot com
Operating system: Windows 2000
PHP version:  4.3.4
PHP Bug Type: Arrays related
Bug description:  dynamically generated form elements using name=foo[] submitted out 
of order

Description:

When submitting a form with elements named using an array (e.g.:
name="foo[]"), the elements appear to be sent in the order in which the
elements are created, and not the order in which they appear in the form's
DOM tree. This can cause information to be sent in a mixed order when the
elements are created in a different order using DOM routines.

Reproduce code:
---
See http://www.oneroad.com/test/phpbug.phtml to run the code, or
http://www.oneroad.com/test/dombug.phps to view it (about 40 lines).



(This server is running 4.0.6, but I have reproduced the bug in 4.3.4 as
well.)



To reproduce:

(1) click "addrow"

(2) choose "1" in the first field, and type "abc" in the second field

(3) click "addrow"

(4) choose "2" in the first field, and type "def" in the second field

(5) change the first select field to "3".

(6) enter "abc" in the second field of the first row.

(7) click "go"



Expected result:

The $_GET array should contain the following:

Array

(

[go] => go

[field1] => Array

(

[0] => 3

[1] => 2

)



[field2] => Array

(

[0] => abc

[1] => def

)



)

Actual result:
--
The $_GET array contained the following. Note the "field2" elements were
sent in the reverse order, because the element in the first row was
dynamically generated *after* the element in the second row.



Array

(

[go] => go

[field1] => Array

(

[0] => 3

[1] => 2

)



[field2] => Array

(

[0] => def

[1] => abc

)



)

-- 
Edit bug report at http://bugs.php.net/?id=27631&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27631&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27631&r=trysnapshot5
Fixed in CVS:   http://bugs.php.net/fix.php?id=27631&r=fixedcvs
Fixed in release:   http://bugs.php.net/fix.php?id=27631&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27631&r=needtrace
Need Reproduce Script:  http://bugs.php.net/fix.php?id=27631&r=needscript
Try newer version:  http://bugs.php.net/fix.php?id=27631&r=oldversion
Not developer issue:http://bugs.php.net/fix.php?id=27631&r=support
Expected behavior:  http://bugs.php.net/fix.php?id=27631&r=notwrong
Not enough info:http://bugs.php.net/fix.php?id=27631&r=notenoughinfo
Submitted twice:http://bugs.php.net/fix.php?id=27631&r=submittedtwice
register_globals:   http://bugs.php.net/fix.php?id=27631&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27631&r=php3
Daylight Savings:   http://bugs.php.net/fix.php?id=27631&r=dst
IIS Stability:  http://bugs.php.net/fix.php?id=27631&r=isapi
Install GNU Sed:http://bugs.php.net/fix.php?id=27631&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27631&r=float


#27631 [Opn]: dynamically generated form elements using name=foo[] submitted out of order

2004-03-17 Thread phpclass at oneroad dot com
 ID:   27631
 User updated by:  phpclass at oneroad dot com
 Reported By:  phpclass at oneroad dot com
 Status:   Open
 Bug Type: Arrays related
 Operating System: Windows 2000
 PHP Version:  4.3.4
 New Comment:

Ah...I'm sorry. I should have tested just a little more before
submitting the test case, and I should have talked about browsers.



The test case reproduces only in Mozilla (I tested with 1.6). It does
NOT reproduce with MSIE 6. And just to make matters more complicated,
Opera 7.23 has a whole different problem (it doesn't show field1 at
all).



With three different browsers, there are three different outcomes.
Given that, there's no clear way to determine whether the bug I've
reported is the result of a browser issue, or a PHP issue.



At first glance, it seems that each browser is submitting the http data
in varying orders, and this is most likely something that PHP can't do
anything about, but this conclusion would be better coming from someone
with more knowledge of how this code works in PHP.


Previous Comments:
----

[2004-03-17 21:45:28] phpclass at oneroad dot com

Description:

When submitting a form with elements named using an array (e.g.:
name="foo[]"), the elements appear to be sent in the order in which the
elements are created, and not the order in which they appear in the
form's DOM tree. This can cause information to be sent in a mixed order
when the elements are created in a different order using DOM routines.

Reproduce code:
---
See http://www.oneroad.com/test/phpbug.phtml to run the code, or
http://www.oneroad.com/test/dombug.phps to view it (about 40 lines).



(This server is running 4.0.6, but I have reproduced the bug in 4.3.4
as well.)



To reproduce:

(1) click "addrow"

(2) choose "1" in the first field, and type "abc" in the second field

(3) click "addrow"

(4) choose "2" in the first field, and type "def" in the second field

(5) change the first select field to "3".

(6) enter "abc" in the second field of the first row.

(7) click "go"



Expected result:

The $_GET array should contain the following:

Array

(

[go] => go

[field1] => Array

(

[0] => 3

[1] => 2

)



[field2] => Array

(

[0] => abc

[1] => def

)



)

Actual result:
--
The $_GET array contained the following. Note the "field2" elements
were sent in the reverse order, because the element in the first row
was dynamically generated *after* the element in the second row.



Array

(

[go] => go

[field1] => Array

(

[0] => 3

[1] => 2

)



[field2] => Array

(

[0] => def

[1] => abc

)



)





-- 
Edit this bug report at http://bugs.php.net/?id=27631&edit=1