PHP form Code

Source: Internet
Author: User

<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.