Checking input from a checkbox or a multiple select : Form Checkbox « Form « PHP






Checking input from a checkbox or a multiple select

 
<?php
$options = array('option 1', 'option 2', 'option 3');

$valid = true;
if (is_array($_GET['input'])) {
    $valid = true;
    foreach($_GET['input'] as $input) {
        if (!in_array($input, $options)) {
            $valid = false;
        }
    }
    if ($valid) {
        //process input
    }
}
?>
  
  








Related examples in the same category

1.Responding to Checkboxes
2.A form with checkboxes using the same name to store multiple values
3.Validating a single checkbox
4.Using Default Checkbox Values