Bug #13718 Updated: form elements with same name problem
| From: | mfischer@php.net | Date: | Thu, 18 Oct 2001 03:14:49 +0000 |
| Subject: | Bug #13718 Updated: form elements with same name problem | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-68183@lists.php.net to get a copy of this message | ||
ID: 13718
Updated by: mfischer
Reported By: jone1941@yahoo.com
Status: Bogus
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.0.6
New Comment:
No, its not 'how it should work'. Image when you write the following code in php:
$interests = "something";
$interests = "new";
Would you expect this ending up with $interests being an array("something",
"new"); ? Certainly not.
So, for you to have an array, like Jani said, append '[]' and you have what you want.
- Markus
Previous Comments:
------------------------------------------------------------------------
[2001-10-17 22:19:52] jone1941@yahoo.com
Here is an example of what I am talking about, try to imagine the interests being dynamically
generated, because it is easy if you already know the names of all of the elements and the form
itself:
form.html:
<html>
<body>
<form action="post.html" method="post">
Baseball: <input type="checkbox" name="interests"
value="baseball"><br>
Teams: <input type="text" name="teams" size="40"
onFocus="interests[0].checked='1'"><br><br>
Football:<input type="checkbox" name="interests"
value="football"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
post.html:
<html>
<body>
<?php
/**
* This is how it should work, interests should be an array
**/
echo("interest 1: $interests[0]<br>\n");
echo("interest 2: $interests[1]<br>\n");
/**
* Instead, the value of $interests is that of the last
* value posted.
**/
echo("$interests");
?>
</body>
</html>
------------------------------------------------------------------------
[2001-10-17 20:10:49] sniper@php.net
Just name them as 'name=varname[]' (add the []'s in the end)
and you'll get an array.
--Jani
------------------------------------------------------------------------
[2001-10-17 16:47:11] jone1941@yahoo.com
The problem exists in the way that php handles the reception of a posted form. If there is more
than one element in a form with the same name and it is posted to a php page, php handles this by
assuming the last element with that name is the correct value for that variable.
In order to provide a proper coexistance with javascript it should treat all variables with that
name as elements of an array.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13718&edit=1