php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21696 Checkbox is strange in POST event
Submitted: 2003-01-16 15:26 UTC Modified: 2003-01-31 13:50 UTC
Votes:39
Avg. Score:3.2 ± 0.9
Reproduced:9 of 19 (47.4%)
Same Version:1 (11.1%)
Same OS:1 (11.1%)
From: ivanpisa at dfm dot ffclrp dot usp dot br Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.3.0 OS: Windows 2000
Private report: No CVE-ID: None
 [2003-01-16 15:26 UTC] ivanpisa at dfm dot ffclrp dot usp dot br
I'm using PHP 4.3.0 as ISAPI in 2 WinXP machines, running Apache 2.0.43. PHP was installed at same folders and I'm using the same PHP.INI. In machine 1, everything works great. In machine 2, everything works great too BUT when I'm using checkbox inside form posting:

echo "<form method=post action=form2.php>";
echo "<br>Are married?";
echo "<input type=checkbox name=married value='s'>";
echo "</form>";

the form2.php is:

<? 
echo "<html><body>";
$married = $HTTP_POST_VARS["married"];
echo "married = ".$married;
echo "</body></html>";
?>

the response is:

Notice: Undefined index: married in form2.php on line 2

In machine 1, forms with checkbox are working great, but in machine 2, it doesn't. Any ideas?? PHP.INI is the same, global_variables are OFF.

Thanks in advance
Ivan Pisa

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-16 15:29 UTC] ivanpisa at dfm dot ffclrp dot usp dot br
(continue)

In fact, the error is simplier: when I run

<?
 echo $a;
?>

in machine 1, it's ok!! But in machine 2, it returns

Notice: Undefined variable: a in test.php on line 2

Any clues???
Thanks
 [2003-01-16 15:39 UTC] tularis@php.net
I'm not sure if it'll make any difference, but try changing this line:

echo '<input type=checkbox name=married value="s">';

since ' is not supported as a valid HTML quote (that is, I THINK it isn't :S)

 [2003-01-16 15:43 UTC] tularis@php.net
ARGH! actually, ignore that comment... I'm talking bs right now :|
 [2003-01-16 16:00 UTC] philip@php.net
Four things:

a) Only checked checkboxes pass values.
b) Why do you expect $a to exist at all?  I see no code that creates $a.
c) Have your test (form2.php) simply be:

print_r($HTTP_POST_VARS);

d) I believe you mean register_globals is off, there is no such thing as global_variables.
e) http://www.php.net/variables.external
 [2003-01-17 05:18 UTC] ivanpisa at dfm dot ffclrp dot usp dot br
First, thanks for your attention.

a) I'm running the same script in other machine, and it's passing NULL ("") string. I suppose the other machine, with the same configuration, should have the same behavior.

b) Do I have to create the variable? Again, it's running in other machine with no problems. And all of my variables are created in the moment I need them. Did I miss something about PHP?

c) I'll test.

d) You are right, sorry, I mean register_globals is off

e) I'll read.
 [2003-01-17 09:10 UTC] hholzgra@php.net
are you sure that your error_reporting settings are really the same on both boxes? (pleas check in phpinfo() output)

the message you see is only produced if E_NOTICE reporting is enabled ...
 [2003-01-17 20:17 UTC] sniper@php.net
If you're really using Apache2, consider moving to Apache 1.3.27 which actually works.

 [2003-01-31 13:50 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2008-09-21 11:12 UTC] jeff at powerupmobile dot com
Same problem with me:
Solaris 10
PHP 5.2.5
Apache 2.2.8

Seems like a simple problem to me, PHP doesn't seem to recognise when a form checkbox is submitted with no value. I guess there are several ways to work around it but would be nice if it recognised it like it recognises and empty text field.
 [2009-05-19 04:25 UTC] mj at ungesundleben dot org
Same problem with PHP 5.1.4, Windows XP and Xampp 1.5.3a.

The problem is especially: How to create a CSV file from post data without explicitely handling checkbox fields by their names if some checkbox fields "vanish"? You will get an unusable CSV file, because the order of the fields gets mismatched.

Workaround:

Inside the form, create checkboxes, which always are checked, but hidden for the user (using CSS), like this:

<input style="display:none" type="checkbox" name="test_chk[]" value="phpbug" checked>
<input class="checkbox" type="checkbox" name="test_chk[]" value="TRUE">

Within a loop ?foreach ($_POST as $key=>$value)? through the post data, you then can do sth. like this:

if (strpos($key,"_chk")) {
if (isset($_POST[$key][1])) {$v='TRUE';} else {$v='FALSE';};
}

Regards,
Maike
 [2013-09-02 09:02 UTC] jmichae3 at yahoo dot com
browser, client side only gives the same results (somename=on for checked, nonexistent for unchecked), even if using DHTML to access the control's arguments from GET (examine the URL) in chrome, IE10, opera, safari (ff buggy, checkboxes don't work for GET in ff23, submitted bug report).
my test case is my DHTML code which uses submit to .html file
http://JesusnJim.com/calculators/finances/calculator-with-estimator-to-save-up-for-item.html
try with and without checkbox checked.

I put in a w3c bug report to this effect for a change to have consistency of operation. something may or may not change in HTML5.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 21:01:27 2024 UTC