foreach (($fruit = $_REQUEST["fruit"]) as $fruitid ) {
if ($fruitid == "notcheched") {
echo 'This fruit was NOT checked: '.$fruitid.' ';
} else {
echo 'This fruit WAS checked: '.$fruitid.' ';
}
}
echo '------------------------------------- ';
}
echo '
';
---
Only the checked boxes gets parsed to php - how do I get the UNchecked
boxes?
Thanks!
Re: parse empty checkbox to php
am 07.09.2007 14:39:58 von luiheidsgoeroe
On Fri, 07 Sep 2007 14:30:35 +0200, thomasriise =
=
wrote:
> I have this code:
>
>
> ---
>
>
> echo 'checkbox tester';
>
> if ($submit){
>
> foreach (($fruit =3D $_REQUEST["fruit"]) as $fruitid ) {
Use $_POST.
>
> if ($fruitid == "notcheched") {
> echo 'This fruit was NOT checked: '.$fruitid.' ';
> } else {
> echo 'This fruit WAS checked: '.$fruitid.' ';
> }
> }
> echo '------------------------------------- ';
> }
>
> echo '
> ';
> ---
>
> Only the checked boxes gets parsed to php - how do I get the UNchecked=
> boxes?
You don't, it's a limitation by HTML. If you want to check which ones ar=
e =
checked and which ones aren't, give them a name (or an index in an array=
=
by 'name=3D"fruit[apple]"', and check with isset. If you don't know for =
=
which ones to check in the receiving script, either store that in a =
session on creating the form, or add a hidden input holding the values:
"thomasriise" wrote in message
news:1189168235.964109.89480@57g2000hsv.googlegroups.com...
> Hi Guys,
>
> I have this code:
>
>
> ---
>
>
> echo 'checkbox tester';
>
> if ($submit){
>
> foreach (($fruit = $_REQUEST["fruit"]) as $fruitid ) {
>
> if ($fruitid == "notcheched") {
> echo 'This fruit was NOT checked: '.$fruitid.' ';
> } else {
> echo 'This fruit WAS checked: '.$fruitid.' ';
> }
> }
> echo '------------------------------------- ';
> }
>
> echo '
> ';
> ---
>
> Only the checked boxes gets parsed to php - how do I get the UNchecked
> boxes?
>
> Thanks!
You don't. This is an HTML problem, not a PHP problem. A checkbox is only
included in the POST array when it is checked ON.
However, there is a workaround. Simply define a hidden field with the same
name as the checkbox immediately BEFORE the real checkbox, and assign it a
value of FALSE or OFF. Only one field with the same name will appear in the
POST array, so if the checkbox is not ON it will allow the hidden FALSE
value to pass through. If the checkbox is ON, then it will replace the value
from the hidden field.