菜单

PHP access to the text box, password domain, button value instance code

2017年11月22日 - PHPer

Getting the value submitted by form elements is the most basic method of operation in form applications. In this section, define the POST () method to submit data and explain the values submitted to form elements in detail.

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

Getting form data is actually getting data from different form elements.

The name in the tag is the attribute that all forms elements have, that is, the name of the form element, and the name attribute is used to obtain the value attribute value of the response when used. So, all the controls added must define the corresponding name attribute values. In addition, the control does not duplicate the name as much as possible, so as not to get the data error.

In the program development process, access to text box, password domain, hidden domain, button, and the value of the text domain method is the same, the use of name attributes to obtain the corresponding value attribute values. This section takes the data information in the text box as an example to explain how to obtain form data. Hope that friends can draw inferences from others, try to complete other control value acquisition.

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

The specific implementation steps are as follows:

(1) create a PHP dynamic page with an arbitrary development tool and name it as index.php.

(2) add a form, a text box, and a submit button. The code is as follows:

  

  

Form

  

   

User name:

Secret code:

     

   

  

(3) in

PHP tags are added at any position outside the form element, and the if conditional statement is used to determine whether the user submits the form. If the judgment condition is established, then the echo statement is used to output the user name and password obtained by the $_POST[] method. The code follows the reality:

<? PHP

If ($_POST[“submit”] = “login”) {/ judge submitted if the name “login button”

/ output using the echo statement to use the $_POST[] method to get the user name and password

Echo “user name:”.$_POST[‘user’] “password:”.$_POST[‘pwd’];

}

&gt?;

Note: the text box in the application value, we must set the name property of the text box right, which should not have spaces; in obtaining the value of the text box, use the text box with the same name must set the name form in the text box, you will not be able to obtain the value of the text box.

(4) enter the running address in the browser, press the Enter key to get the running result as shown in the picture below:

Code is as follows

发表评论

电子邮件地址不会被公开。