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