Using checkboxes as a means of confirmation.
Posted: Mon Jan 04, 2010 5:36 am
If I added a checkbox to a form asking a visitor to check it before the form can be submitted, could this be fooled somehow and the form submitted without the checkbox checked?
I would use isset() to check if the checkbox had been set and I would also check the value of the checkbox and from that determine whether the code should execute.
Code: Select all
<html>
Check tick box before submitting form
<form method="post" action="processPage.php">
<input type="checkbox" name="checkBoxToCheck" value="Y" />
<input type="submit" value="Submit" />
</form>
</html>
I would use isset() to check if the checkbox had been set and I would also check the value of the checkbox and from that determine whether the code should execute.
Code: Select all
<?php
if ( isset($_POST['checkBoxToCheck']) || ($_POST['checkBoxToCheck'] == '' ) {
// code to execute
}
else {
// alternate code
}
?>