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: