/* PHP template for input validation 1. paste contents of this file after the 3. delete unwanted checks on $_POST[] variables below 4. Done! The remaining steps are optional for advanced users 4a. to validate input from several HTML forms, paste the next line in each HTML form that is to be validated and adjust the value of the hidden variable 4b. you may add your own input checks below */ if ($_POST[from_page] == "1") //HTML form to be validated contains hidden variable "from_page" with value "1" { if ($_POST[apples] < "1") //value of input field is less than 1 { echo "Please tell us whether you like apples."; echo "

back"; exit; } if ($_POST[peaches] == "" || $_POST[age] == "") //one or both input fields are empty { echo "Please tell us your age and whether you like peaches!"; echo "

back"; exit; } if (!is_numeric ($_POST[age])) //age is not numeric { echo "Please indicate your age in full years using numbers only!"; echo "

back"; exit; } if (strlen($_POST[age]) < 2) //age is less than 2 characters long { echo "Are you really that young?"; echo "

back"; exit; } }