PHP Forms and User Input (Cont.)


PHP Radio Buttons
Radio buttons are used when you want the user to select one of a limited number of choices.

HTML
12_1.php
 <form method="post" action="12_1.php">
  <input name="sex" type="radio"
    value="male"> Male
  <input name="sex" type="radio"
    value="female" checked> Female
  <input type="submit" name="act"
    value="Check"> 
 </form>
 <html><body>
 <?php
  echo  "Pick: $_POST[act]";
  echo  " & $_POST[sex]";
 ?>
 </body></html>
Male   Female      

PHP Checkboxes
A radio button is a way to restrict users to having only one choice. Like radio buttons, checkboxes are used to give visitors a choice of options. Whereas radio buttons restrict users to only one choice, you can select more than one option with checkboxes.

HTML
12_2.php
 <form method="post"
   action="12_2.php">
  <input name="hs[]" type="checkbox"
    value="Biking"> Biking
  <input name="hs[]" type="checkbox"
    value="Hiking"> Hiking
  <input name="hs[]" type="checkbox"
    value="Reading"> Reading
  <input type="submit" name="act"
    value="Check"> 
 </form>
 <html><body>
 <?php
  echo "Pick: ";
  $hs = $_POST[hs];
  foreach ( $hs as $h )
   echo  "$h ";
 ?>
 </body></html>
Biking   Hiking   Reading      




      My girlfriend treats me like a God.    
      She ignores my existence and only talks to me when she needs something.