Form Validation



Question : Write a program that will take an input in normal HTML form. When you submit the form, the number entered will be checked if it is less than or equal to 10. If the number is less than 10, it will say - the number is less than or equal to 10. If the number is greater than 10, it will say - the number is greater than 10.

Answer

Here is the example code to accomplish this task.

<form action="form1.php" method="post">

Enter Value <input type="text" name="number" value = "0" /><br />
<br />
<input type="submit" name="checkform" value="Submit" />
</form> 
<br />
<?
if  (isset($_POST['checkform'])) 
{
if  (( $_POST["number"] ) <=10 )  
	echo "The number you entered is less than or equal to  10";
     else
	 echo "The number you entered is Greater than 10";
     
}
?>


Notice that we do not do any checking on whether the entered text is digit or non digit. In complex situation you may like to apply some kind of validation to test if the number entered is digits only.