RE: [PHP] checkbox checked?
| From: | Grant Walters | Date: | Sun, 22 Oct 2000 02:07:24 +0000 |
| Subject: | RE: [PHP] checkbox checked? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21619@lists.php.net to get a copy of this message | ||
> > > How would I check if a checkbox is checked? I have a form that will
> > > require the one checkbox in it, to be checked. I have learned how to
> > > validate mail, names, ETC, but I have run into a wall on this one.
> >
> > I believe that PHP (3 anyway) doesn't set the variable in
> HTTP_POST_VARS for
> > unchecked check boxes so...
> >
> > If you have
> >
> > <input type="checkbox" name="Contact_Requested"
> > value="True">
> Please contact
> > me as soon as possible regarding this matter
> >
> > In a checked situation there will be a variable called
> Contact_Requested set
> > (or HTTP_POST_VARS['Contact_Requested'])
> >
> > If it is unchecked before the form is submitted then it won't be there.
> >
>
> if ($checkbox <=0);
> echo "you must accept the rules, before you can join";
> else
>
> I don't know if <=0 will work.
>
Just use isset as in:
if (!isset($checkbox)) {
echo "you must accept the rules, before you can join";
} else {
Regards
Grant Walters
Walters & Associates, P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175, CellPhone 025488265