PHP programming daily must-learn form validation, PHP programming Form _php Tutorial

Source: Internet
Author: User
Tags learn php programming php form php form processing php form validation

PHP programming daily must-learn form validation, PHP programming form


This article explains the implementation of PHP form verification, share to everyone for reference, the specific content 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 Validation Complete instance

 <?php//defines the variable and sets it to a null value $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"]);   Checks whether the name contains letters and whitespace characters the//preg_match () function retrieves the pattern of the string, or returns True if the pattern exists, otherwise false.    if (!preg_match ("/^[a-za-z]*$/", $name)) {$NAMEERR = "only allow letters and spaces";  }} if (Empty ($_post["email")) {$EMAILERR = "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+&@#\/%?=~_|!:,.;] *[-a-z0-9+&@#\/%=~_|]    /i ", $website)) {$WEBSITEERR =" Invalid URL "; }}}function Test_input ($data) {//Remove unnecessary characters from user input data (extra spaces, tabs, line breaks) $data = TriM ($data);  Remove the backslash (\) $data = Stripslashes ($data) in the user input data;  Converts a special character to an HTML entity $data = Htmlspecialchars ($data); return $data;}? >

PHP Validation Example

* Required Fields

<?phpecho "

Your input:

"Echo $name; echo"
"Echo $email; echo"
"Echo $website; echo"
";? >

I hope this article will help you learn PHP programming.

Articles you may be interested in:

    • Regular expressions for common forms validation under PHP
    • PHP Form Validation Implementation code
    • Summary of three common forms validation functions used in PHP development
    • How to use PHP form validation 3 functions isset (), Empty (), Is_numeric ()
    • PHP TP Validation form with AutoFill function code
    • Implementation of form validation based on Php+ajax
    • PHP user registration page using JS to form validation specific instances
    • thinkphp Form Auto-Submit Validation Example Tutorial
    • thinkphp form Auto-Validate instance
    • thinkphp implementing automatic validation of forms

http://www.bkjia.com/PHPjc/1105381.html www.bkjia.com true http://www.bkjia.com/PHPjc/1105381.html techarticle PHP Programming every day must learn form validation, PHP programming form This article explains the PHP form verification implementation method, share to everyone for reference, the specific content as follows 1.PHP form processing W ...

  • Related Article

    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.