Basic PHP Tutorial-form validation (required, post-commit data retention)

Source: Internet
Author: User
A few elements recorded in form validation

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

2.$_server["Php_self"] is a super global variable that returns the current page script name

3.trim () to remove extra spaces, etc.

4.stripslashes () to remove multiple input backslashes from the user

Second simple form validation functions

function Test_input ($str) {$str = Trim ($STR),//$str = Stripslashes ($STR),//Remove the backslash $str = Htmlspecialchars of the user input ($str );//convert special character to normal character return $str;}
Third, the form must fill in the prompt code

1.php code, verify that the input box is empty, add an error message for display in HTML, non-null to validate and process input

PHP code snippet for inserting output error information in 2.HTML code such as *

$EMAILERR to save the error information variable, the start is empty.

Simple example:

  
 

* Must be filled

"; echo" Name: ", $name; echo"
E-mail: ", $email; echo"
URL: ", $website; echo"
Comment: ", $area; echo"
Gender: ", $gender;? >

To display a drawing:


Iv. Retention of form data

In the above code, just change the followingAdd a PHP fragment to the tag:

For elements, simply add the PHP fragment between <textarea>

On the radio, more troublesome, inAdd code in:

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