php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14674 $HTTP_POST_VARS not finding all posted variables
Submitted: 2001-12-23 12:18 UTC Modified: 2001-12-23 15:46 UTC
From: robert at montanasoft dot com Assigned:
Status: Closed Package: Variables related
PHP Version: 4.1.0 OS: Windows 2000 Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 - 29 = ?
Subscribe to this entry?

 
 [2001-12-23 12:18 UTC] robert at montanasoft dot 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-23 12:23 UTC] 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:31 UTC] robert at montanasoft dot 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 13:24 UTC] 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 15:46 UTC] daniel@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 00:01:28 2024 UTC