Php basic tutorial-form verification (required, data retained after submission)

Source: Internet
Author: User
Php basic tutorial-form verification (required, data retained after submission) I. Several element records used in form verification

1. htmlspecialchars () is used to escape special characters entered by the user into common characters. for example, HTML characters such as <and> are replaced with <and>

2. $ _ SERVER ["PHP_SELF"] is a super global variable. the script name on the current page is returned.

3. trim () is used to delete unnecessary spaces.

4. stripslashes () is used to delete multiple user-input backlash.

2. a simple form verification function

Function test_input ($ str) {$ str = trim ($ str); // remove spaces and other $ str = stripslashes ($ str ); // remove the backslash $ str = htmlspecialchars ($ str); // returns $ str ;}
3. prompt code for required items in the form

1. in php code, if the verification input box is empty, an error message is added for display in HTML. if it is not empty, the input is verified and processed.

2. Insert the php code snippet with the output error information in HTML code, as shown in *

$ EmailErr is the variable used to save the error message. the start value is null.

Simple example:

  
 

* Required

"; Echo" name: ", $ name; echo"
Email: ", $ email; echo"
URL: ", $ website; echo"
Comment: ", $ area; echo"
Gender: ", $ gender;?>

Show cut chart:


IV. table data retention

In the above code, you only need to change the following:Add a PHP clip to the tag:

PairAdd the php fragment to the <textarea>Between

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