Page 1 of 1

Using checkboxes as a means of confirmation.

Posted: Mon Jan 04, 2010 5:36 am
by social_experiment
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?

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
  }
?>
 

Re: Using checkboxes as a means of confirmation.

Posted: Mon Jan 04, 2010 6:08 am
by iamngk
you have to change if condition.

Code: Select all

<?php
  if ( isset($_POST['checkBoxToCheck']) && $_POST['checkBoxToCheck'] == 'Y' ) {
     // code to execute
  }
  else {
     // alternate code
  }
?>

Re: Using checkboxes as a means of confirmation.

Posted: Mon Jan 04, 2010 8:05 am
by social_experiment
Ok, so that both conditions are met at the same time.

Thanks :)