Validating a radio button : Radio Button « Form « PHP






Validating a radio button

 
<?php
$choices = array('eggs' => 'E',
                 'toast' => 'T',
                 'coffee' => 'C');
foreach ($choices as $key => $choice) {
   echo "<input type='radio' name='food' value='$key'/> $choice \n";
}

if (! array_key_exists($_POST['food'], $choices)) {
    echo "You must select a valid choice.";
}
?>
  
  








Related examples in the same category

1.Checking input from a radio button or a single select
2.Form radio buttons