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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…