PHP Gets the value of the form's form text box, password field, button

Source: Internet
Author: User
Getting the value submitted by a FORM element is the most basic way to do it in a form application. In this section, the POST () method is defined to submit the data, which is explained in detail in obtaining the values submitted by the form element.

Gets the value of the text box, password field, button

Getting the form data is actually getting the data for different form elements. The name in the <form> tag is the attribute that all form elements have, that is, the names of the form elements that need to be used with the Name property to get the value of the response. Therefore, all the controls that you add must define the corresponding Name property value. In addition, the control should be named as little as possible to avoid errors in getting the data.

During program development, the method of getting the values of a text box, password field, hidden field, button, and text field is the same, using the Name property to obtain the value of the corresponding Value property. This section explains how to get the form data by taking the data information in the text box as an example. Hopefully friends will be able to extrapolate and try to get the other control's values.

Use the login instance below to learn how to get the information for a text box. In the example below, if the user clicks the login button, the user name and password are obtained.

The specific implementation steps are as follows:

(1) Use any one of the development tools to create a PHP dynamic page and name it index.php.

(2) Add a form, a text box, and a Submit button, as shown in the following code:

<! DOCTYPE html>

(3) Add PHP tags anywhere outside of the <form> form element, use the IF condition statement to determine if the user submitted the form, and if so, use the Echo statement to output the user name and password using the $_post[] method. The code follows the reality:

<?PHPIF ($_post["submit"] = = "Login") {             //Determine if the submitted button name is "Login"//Use the Echo statement output using the $_post[] method to obtain the user name and password echo "User name:". $_post[' user '. "<BR > Password:". $_post[' pwd ';}? >

Note: When applying a text box, be sure to correctly set the Name property of the text box, where there should be no spaces, and when you get the value of the text box, use the same text box name you set in the form text box, or you will not be able to get the value of the text box.

(4) Enter the running address in the browser and press ENTER to get the result as shown:

Related Article

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.