Passing nested arrays to $_REQUEST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DonGar
Forum Newbie
Posts: 2
Joined: Sun Jun 22, 2003 12:47 am

Passing nested arrays to $_REQUEST

Post by DonGar »

I'm currently testing with PHP 4.3.1 as an Apache module. The pattern I normally follow is to lump all form fields together into a single array and then perform processing against the array. However, nested array do not seem to be importing correctly.

Forms A and B pass values to handler.php as I would expect. Form C does not. I detail my expectations below...

Form A:

<form action=handler.php>
<input type="hidden" name="test[first]" value="1">
<input type="hidden" name="test[second]" value="2">

<input type="submit" name="Submit" value="Submit">
</form>

Form B:

<form action=handler.php>
<input type="hidden" name="test[]" value="1">
<input type="hidden" name="test[]" value="2">

<input type="submit" name="Submit" value="Submit">
</form>

Form C:

<form action=handler.php>
<input type="hidden" name="outer[test[]]" value="1">
<input type="hidden" name="outer[test[]]" value="2">

<input type="submit" name="Submit" value="Submit">
</form>


Form A produces something like:

$_REQUEST['test'] = array('first' => 1, 'second' => 2);

Form B produces something like:

$_REQUEST['test'] = array(1, 2);

Form C was expected to produce something like:

$_REQUEST['outer'] = array('test' => array(1, 2));

Instead it produced something like this:

$_REQUEST['test'] = array('test[' => 2);


This seems like a bug to me. Does anyone know which (if any) versions of PHP handle this correctly, or where I can go to file a bug report?


PS:
These forms are a simplified version of the forms I'm really working with. The behavior with something this simple may not be quite the same. I would try to produce tested simple versions before filing a real bug report.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<!-- Form C: -->
<form action="handler.php" method="POST"><!-- or method="GET" which is default -->
	<input type="hidden" name="outer&#1111;test]&#1111;]" value="1" />
	<input type="hidden" name="outer&#1111;test]&#1111;]" value="2" />
	<input type="submit" name="Submit" value="Submit" />
</form>
DonGar
Forum Newbie
Posts: 2
Joined: Sun Jun 22, 2003 12:47 am

Post by DonGar »

I guess I was too quick to cry "Bug"! As is usual in such cases, the correct answer is obvious... after the fact.

Thanks!
Post Reply