How come checkbox state is not always passed along to PHP script?
- by George Edison
I have an HTML form:
<form action='process.php' method='post'>
<input type='checkbox' name='check_box_1' /> Check me!<br>
</form>
Here is a section from the PHP script process.php:
echo (isset($_POST['check_box_1']))?'Set':'Not set';
The output of the script when the checkbox is set is
Set
But when the checkbox is not set, the output is:
Not set
Why is this? This seems like a very poor design because my PHP script checks a number of $_POST variables to make sure they were passed along to the script. When the $_POST['check_box_1'] value is not set, then how do I know whether the script failed to pass along the value or the checkbox was just not set?