PHP Processing Web Form

Source: Internet
Author: User
PHP Form Operations
When we work with HTML forms and PHP forms, it's important to remember that any form element in an HTML page can be used automatically for PHP scripts:
Examples of forms:


The above HTML page contains two input boxes [inputs field] and one submit [submit] button. When the user fills out the information and clicks the Submit button, the form's data will be sent to the "welcome.php" file.
The "welcome.php" file looks like this:

Welcome 
 
   .
You is years old.


The script above will output the following result:
Welcome John.
You is years old.

form validation [form Validation]

The information entered by the user should be verified as far as possible through the client script (e.g. JavaScript) browser, and the validation of information through the browser can improve efficiency and reduce the download pressure on the server.

If the information entered by the user needs to be stored in the database, then you must consider validating the validation on the server side. The best way to verify the validity of information on the server is to send the form information to the current page for validation instead of being transferred to another page for validation. With the above method, if there is an error in the form, the user can get the error message directly on the current page. This makes it easier to find the error messages that exist.

The PHP $_get variable gets the value from the form using the Get method.

$_get variable

The $_get variable is an array that contains the name [name] and value [value], which are sent through the HTTP GET method and can be exploited.
The $_get variable uses "Method=get" to obtain form information. The information sent through the Get method is visible (it will be displayed in the browser's address bar), and it has a length limit (the total length of the information cannot exceed 100 characters [character]).
Case


When the user clicks the "Submit Submission" button, the URL is displayed
The "welcome.php" file can use the "$_get" variable to obtain the form data (note: The name in the Form field [form Fields] will automatically be the ID keyword in the "$_get" array):

Welcome 
 
   .
You are years old!

Why use "$_get"?

Important: When you use the "$_get" variable, all variable names and variable values are displayed in the URL address bar, so when you send a message that contains a password or some other sensitive information, you can no longer use this method. Because all the information is displayed in the URL field, we can put it as a tag in the Favorites folder. This is useful in many cases.

Note: The HTTP get method does not apply if the value of the variable that needs to be sent is too large. The amount of information sent cannot exceed 100 characters.
$_request variable
The PHP $_request variable contains the contents of $_get, $_post, and $_cookie.
PHP $_request variables can be used to get form data sent through both "get" and "POST" methods.
Case

Welcome 
 
   .
You are years old!

The PHP $_post variable is used to obtain form variables that are sent by method = "POST".
$_post variable

The $_post variable is an array containing the name [name] what value [value] (these names and values are sent via the HTTP POST method and can be exploited)
The $_post variable uses "method=post" to obtain form information. The information sent through the Post method is not visible, and it does not have a limit on the length of the information.
Case


When the user clicks the "Submit Submission" button, no form data will be included in the URL
The "welcome.php" file can use the "$_post" variable to obtain the form data (note: The name in the Form field [form Fields] will automatically be the ID keyword in the "$_post" array):

Welcome 
 
   .
You are years old!



Why use $_post?
Variables sent over HTTP POST are not displayed in URLs
There is no limit to the size of variables
However, because the variable cannot be displayed in the URL, it is not possible to store the page as a tag in the Favorites folder.
$_request variable
PHP $_request variable contains $_get, $_post, and $_cookie content
PHP $_request variables can be used to get form data sent through both "get" and "POST" methods.
Case

Welcome 
 
   .
You are years old!
  • 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.