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: