Forum Moderators: coopster

Message Too Old, No Replies

Record Unchecked Checkbox

         

fib_81

9:02 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Hi,

Is there a way to record a checkbox that is not checked?

Thanks
Fib_81

ironik

9:09 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



PHP only stores the checkbox as a $_POST or $_GET variable if it has been checked, otherwise it is ignored. The only way to tell if a checkbox has been ignored is to know the name of the checkbox beforehand and to test for its existence:

if (isset($_POST['checkbox']))
{
// apply action because 'checkbox' has been ticked
}

coopster

11:13 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, fib_81.

The point ironik brings up pretty much nails it down. You served up the form in the first place, so you already know what options are in the checkbox. If it is just static HTML in a page, you could always change that by building the checkbox from an array of values or database options. When checking the POSTed data, just compare to the same array of values again.

fib_81

12:06 am on Mar 11, 2005 (gmt 0)

10+ Year Member



Hi Everyone,

Thanks for responding. I try the suggestions. Thanks again.

Fib_81