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
radio.php
1<form method="post" action="radio.php">
2 <input name="sex" type="radio"
3   value="male"> Male
4 <input name="sex" type="radio"
5   value="female" checked> Female
6 <input type="submit" name="act"
7   value="Check">
8</form>
1<html><body>
2<?php
3 echo  "Pick 🠞 " . $_POST['act'];
4 echo  " & " . $_POST['sex'];
5?>
6</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
checkbox.php
01<form method="post"
02  action="checkbox.php">
03 <input name="hs[]" type="checkbox"
04   value="Biking"> Biking
05 <input name="hs[]" type="checkbox"
06   value="Hiking"> Hiking
07 <input name="hs[]" type="checkbox"
08   value="Reading"> Reading
09 <input type="submit" name="act"
10   value="Check">
11</form>
1<html><body>
2<?php
3 echo "Pick 🠞 ";
4 $hs = $_POST['hs'];
5 foreach ( $hs as $h )
6  echo  "$h ";
7?>
8</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.