Bug #14674 Updated: $HTTP_POST_VARS not finding all posted variables
| From: | daniel@php.net | Date: | Sun, 23 Dec 2001 20:46:52 +0000 |
| Subject: | Bug #14674 Updated: $HTTP_POST_VARS not finding all posted variables | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-74881@lists.php.net to get a copy of this message | ||
ID: 14674
Updated by: daniel
Reported By: robert@montanasoft.com
Old Status: Bogus
Status: Closed
Bug Type: Variables related
Operating System: Windows 2000 Pro
PHP Version: 4.1.0
New Comment:
why network sniffer? just METHOD=GET and you'll get all variables.
this behaviour is absolutely intended, thus bogus, thus closed. NON bug.
tip: use <select> instead if radio if you want to have a true/false decision. radiobuttons are
intended to have [n] elements.
Previous Comments:
------------------------------------------------------------------------
[2001-12-23 13:24:11] derick@php.net
I just checked it with a network sniffer:
[ASCII dump]
0000 ........ ......E. ....@.@. 1v...... .....P.? .j...s.. ........ ........
0040 ..Conten t-type: applicat ion/x-ww w-form-u rlencode d..Conte nt-Lengt
0080 h: 19... .submitb utton=Su bmit
It really doesn't send the radioutton with it.
Derick
------------------------------------------------------------------------
[2001-12-23 12:31:49] robert@montanasoft.com
Hi Derick:
Thanks for responding so quickly.
I'm a little confused. If I create an ASP script, it is able to see the variable of a blank,
unselected radio button without difficulty. And that is using the same browser -- so it is
definitely sending all of the form variables.
I'm probably missing something, but why would it work in ASP and not in PHP?
Is there anything I can do to help?
------------------------------------------------------------------------
[2001-12-23 12:23:13] derick@php.net
This is not a bug in PHP, but a browser issue. You can either set one radio button as a default
value, or you can use:
if (isset ($HTTP_POST_VARS['radiobutton'])) {
}
to see if it is set at all.
But as the browser does not send the parameter (I tested this), there is little PHP can do if it
doesn't see it.
Derick
------------------------------------------------------------------------
[2001-12-23 12:18:31] robert@montanasoft.com
- Win2K Pro, running Apache 1.3.22 (standard Win32 setup)
- PHP 4.1.0, Win32 Binaries -- no changes to ini file (except "include_path =" and
"SMTP ="
- WHAT I DID:
I created a simple html form with the "POST" method:
<html>
<body>
<form action="test1.php" method="post">
<input type="radio" name="radiobutton" value="True">True
<input type="radio" name="radiobutton" value="False">False
<input type="submit" name="submitbutton" value="Submit">
</form>
</body>
</html>
Next I created "test1.php" to receive those posted variables (as you can see I tried
several methods of checking them):
<?
foreach ($HTTP_POST_VARS as $var => $value) {
echo "$var = $value<br>\n";
}
echo "<P>Values submitted via POST method:<br>";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
echo "$key => $val<br>";
}
?>
- WHAT I WANTED TO HAPPEN:
I wanted to use the $HTTP_POST_VARS array to validate the form. If the end user forgets to select
one of the radio button options, that should show up in $HTTP_POST_VARS as a variable with a
"" value, which would allow me to post a validation error message to the user.
- WHAT ACTUALLY HAPPENED:
If the end user forgets to select one of the radio options, the posted variable doesn't show up
in $HTTP_POST_VARS !!
The output of the php script is:
// begin test1.php output (with no radio button selected):
submitbutton = Submit
Values submitted via POST method:
submitbutton => Submit
// end test1.php output
If one of the buttons is pre-selected, it will show up as a variable in the $HTTP_POST_VARS. Here
is the output:
//begin test1.php output (with radio button selected):
radiobutton = False
submitbutton = Submit
Values submitted via POST method:
radiobutton => False
submitbutton => Submit
// end test1.php output (with radio button pre-selected)
-WHY THIS IS A SERIOUS PROBLEM:
As I'm sure you can imagine, this makes it impossible to create a generic validation script
that is capable of validating radio buttons.
If I create a simple $radiobutton variable (the same name as the form input), It will work to
validate the form if the user has not remembered to select a radio button.
But this will require me to manually validate radio buttons in my script, rather than being able to
create and use a generic validation script. I've created a generic script in ASP that uses the
"request.form" method to validate all form fields and it works properly with radio
buttons.
Also, I've tested the $HTTP_POST_VARS array with all other input types, and it finds all other
posted variables, even if they are blank.
What can I do?
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14674&edit=1