Php programming forms are required every day. Php programming forms are required to be verified every day. This document describes how to implement php form verification. the content of this article is as follows. PHP form processing w php programming forms that must be learned every day, php programming forms
This article explains how to implement php form verification and shares 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.
Articles you may be interested in:
- Regular expressions used for form verification in php
- Php form verification implementation code
- Summary of the usage of the three form verification functions commonly used in PHP development
- How to use ISSET (), empty (), and is_numeric () functions for PHP form verification
- Php tp verification form and auto-fill function code
- Detailed description of form verification based on PHP + Ajax
- The php user registration page uses js for form verification of specific instances
- ThinkPHP automated form submission verification example tutorial
- Automatically verifies the ThinkPHP form.
- Automatic form verification using thinkPHP
Examples in this article explains how to implement php form verification and share it with you for your reference. the specific content is as follows: 1. PHP form processing w...