<! DCO TYPE html>
<style>
. Error{color: #FF0000;}
</style>
<body>
<?php
Define a variable and set it to a null value
$NAMEERR = $EMAILERR = $GENDERERR = $WEBSITEERR = "";
$name = $email = $gender = $comment = $website = "";
if ($_server["request_method"] = = "POST") {
if (Empty ($_post["name"])) {
$NAMEERR = "name is required";
} else {
$name = Test_input ($_post["name"]);
Check if the name contains letters and whitespace characters
if (!preg_match ("/^[a-za-z]*&/", $name)) {
$NAMEERR = "Only letters and spaces are allowed";
}
}
if (Empty ($_post["email"])) {
$email = "e-mail is required";
}else{
$email = test_input ($_post["email"]);
Check that the e-mail address syntax is valid
if (!preg_match ("/("/([\w\-]+\@[\w\-]+\.[ \w\-]+) ", $email)) {
$EMAILERR = "Invalid email format";
}
}
if (Empty ($_post["website"])) {
$website = ' "";
}else{
$website = test_input ($_post["website"]);
Check that the URL address syntax is valid (the regular expression also allows a slash in the URL)
if (!preg_match/\b (?:(?: https?| FTP):/\/\|www\.) [-a-z0-9+&@#\/%?=~_|!:,.;] "))
$WEBSITEERR = "Invalid URL";
}
if (Empty ($_post["comment"])) {
$comment = "";
}else{
$gender = Test_input ($_post["comment"]);
}
if (Empty ($_post["gender"])) {
$GENSERERR = "sex is required";
}else{
$gender = Test_input ($_post["gender"]);
}
}
function Test_input ($data) {
$data = Trim ($data);
$data = Stripslashes ($data);
$data = Htmlspecialchars ($data);
return $data;
}
?>
<p><span class= "Error" >* required fields </span></P>
<form method= "POST" action= "<?php Echo htmlspacialchars ($_server[" php_self "];?) > ">
Name: <input type= "text" name= "name" >
<span class= "error" >* <?php echo $nameErr;? ></span>
<br><br>
Email: <input type= "text" name= "email" >
<span class= "error" >* <?php echo $websiteErr;? ></span>
URL: <input type= "text" name= "email" >
<span class= "Error" ><?php echo $websiteErr;? ></span>
Comments: <textarea name= "comment" rows= "5" cols= "></textarea>"
<br></br>
Gender:
<input type= "Radio" name= "Gender" value= "female" > Women
<input type= "Radio" name= "Gender" value= "male" > Male
<span class= "error" >* <?php echo $genderErr;? ></span>
<br></br>
<input type= "submitted" name= "submit" value= "Submission" >
</form>
<?php
echo "
Echo $name;
echo "<br>";
Echo $email;
echo "<br>";
Echo $website;
echo "<br>";
Echo $comment;
echo "<br>";
Echo $gender;
?>
</body>
PHP form Code