Daily form verification required for php programming

Source: Internet
Author: User
Php programming requires forms verification every day. it studies php form processing and implements php form verification with a complete example, if you are interested, you can refer to the example in this article to explain how to implement php form verification and share it with you for your reference. the specific content is as follows:

1. PHP form processing
Welcome.html

  

Welcome. php

 Welcome <? Php echo $ _ POST ["name"];?>
Your email address is: <? Php echo $ _ POST ["email"];?>

2. PHP form verification complete instance

<? Php // define the variable and set it to null $ nameErr = $ emailErr = $ websiteErr = ""; $ name = $ email = $ website = ""; if ($ _ SERVER ["REQUEST_METHOD"] = "POST") {if (empty ($ _ POST ["name"]) {$ nameErr = "name is required";} else {$ name = test_input ($ _ POST ["name"]); // check whether the name contains letters and blank characters // The preg_match () function retrieves the string mode. if the mode exists, true is returned; otherwise, false is returned. If (! Preg_match ("/^ [a-zA-Z] * $/", $ name) {$ nameErr = "only letters and spaces are allowed ";}} if (empty ($ _ POST ["email"]) {$ emailErr = "email is required ";} else {$ email = test_input ($ _ POST ["email"]); // check whether the email 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 whether the URL address syntax is valid (the regular expression also allows the slash in the URL) if (! Preg_match ("/\ B (? :(?: Https? | Ftp): \ // | www \.) [-a-z0-9 + @ # \/%? = ~ _ |! :,.;] * [-A-z0-9 + @ # \/% = ~ _ |]/I ", $ website) {$ websiteErr =" invalid URL ";}} function test_input ($ data) {// remove unnecessary characters (extra spaces, tabs, and line breaks) from user input data $ data = trim ($ data ); // delete the backslash (\) $ data = stripslashes ($ data) in user input data; // Convert Special characters into HTML entities $ data = htmlspecialchars ($ data ); return $ data ;}?> PHP verification instance

* Required fields

<? Phpecho "your input:"; echo $ name; echo"
"; Echo $ email; echo"
"; Echo $ website; echo"
";?>

I hope this article will help you learn php programming.

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.