Page 1 of 1
problem with checkbox
Posted: Wed Jan 30, 2008 4:34 pm
by acheoacheo
If that checkbox remains unchecked I can't retreive the value "off" in the $_POST variable when the form is submitted.
However if it is checked then I can retreive it...what's the problem??????????
Code: Select all
<input type="checkbox" name="Agreement" id="Debug" />
Code: Select all
if ($_POST['Agreement'] == "off"){
$error_message["agreement"] = "You haven't read the Terms of use.";
$isOk = 0;
}
Re: problem with checkbox
Posted: Wed Jan 30, 2008 4:54 pm
by Christopher
acheoacheo wrote:If that checkbox remains unchecked I can't retreive the value "off" in the $_POST variable when the form is submitted.
Absolutely correct!
acheoacheo wrote:However if it is checked then I can retreive it...what's the problem??????????
Code: Select all
if (! isset($_POST['Agreement'])){
$error_message["agreement"] = "You haven't read the Terms of use.";
$isOk = 0;
}
Re: problem with checkbox
Posted: Wed Jan 30, 2008 6:37 pm
by RobertGonzalez
empty() will be of great value to you here.
Re: problem with checkbox
Posted: Wed Jan 30, 2008 7:45 pm
by acheoacheo
thank you!
Re: problem with checkbox
Posted: Wed Jan 30, 2008 10:04 pm
by Festy
If the checkbox is checked, you get the value 'on' but if it's unchecked you don't get any value at all (not even off) or even the refrence of your checkbox object for that matter.
Re: problem with checkbox
Posted: Thu Jan 31, 2008 11:22 am
by RobertGonzalez
That is why you check empty() on it. If it is empty then it is not checked, otherwise, it is.