Advance Web Programing Lecture: Anwar H. Al-Saleh
13
E-mail: <input type="text" name="email"><br>
<input type="submit" value="Send">
</form>
<hr>
<?php
// sends the submitted form data to the page itself using $PHP_SELVE
$name =$_POST['name']; $email =$_POST['email'];
if ($name=="" )
echo "Name is required";
// check if name only contains letters and whitespace
elseif (!preg_match("/^[a-zA-Z ]*$/",$name))
echo "Name : Only letters and white space allowed";
else
echo "your Name is $name ";
echo "<br> ----------------- <br>";
if ($email=="" )
echo "E-mail is required";
// check if e-mail address is well-formed
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL))
echo "please enter correct email";
else
echo "your E-mail is $email ";
?>
PHP 5 Complete Form Example
Here is the complete code for the PHP Form Validation Example:
Example
<h2>PHP Form Validation Example</h2>
<form action="<?php echo $PHP_SELVE ; ?>" method="post">
Name: <input type="text" name="name" > <br><br>
E-mail: <input type="text" name="email"> <br><br>
Website: <input type="text" name="website" > <br><br>
Comment: <textarea name="comment" rows="5" cols="40"> </textarea> <br><br>
Gender:
<input type="radio" name="gender" value="female"> Female
<input type="radio" name="gender" value="male"> Male <br><br>
Your Foverat Languag : <br>