Introduction to How PHP processes forms

Source: Internet
Author: User

A useful feature of PHP is the way it handles PHP forms. The very important principle you need to understand is that any elements of the form will automatically take effect in your PHP script. See "Variables outside of PHP" in this manual for more information and examples of using forms in PHP. Here is an example of an HTML form:

Example: a simple HTML form

<form action="action.php" method="POST">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit">
</form>

There is nothing special about the form, which does not use any special identifiers. When the user fills out the form and clicks on the Submit button, the page action.php will be invoked. In this file, you can add the following:

Example: Print data from a form

Hi <?php echo $_POST["name"]; ?>.
You are <?php echo $_POST["age"]; ?> years old.

The output of this script might be:

Hi Joe.
You are 22 years old.

The script's work should already be clear, and there is no more complex content. PHP will automatically set the $_post["name" and $_post["age" variables for you. Before that we used the automatic global variable $_server, and now we've introduced the automatic global variable $_post, which contains all the POST data. Notice how our form submits the data (method). If we can use the Get method, the information in the form will be stored in the automatic global variable $_get. If you are not concerned with the source of the request data, you can also use the automatic global variable $_request, which contains all the data for GET, POST, COOKIE, and FILE.

This example is just an example of getting started! Provides a quick way into the world of PHP.

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.