php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27631 dynamically generated form elements using name=foo[] submitted out of order
Submitted: 2004-03-17 21:45 UTC Modified: 2004-03-17 23:27 UTC
From: phpclass at oneroad dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.4 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-03-17 21:45 UTC] 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
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-17 22:03 UTC] phpclass at oneroad dot com
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.
 [2004-03-17 23:27 UTC] edink@php.net
Depends on the browser used -- not a PHP bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 11:01:33 2024 UTC