PHP obtains the example code of the text box, password field, and button value,

Source: Internet
Author: User

PHP obtains the example code of the text box, password field, and button value,

Obtaining the submitted value of a form element is the most basic operation method in a form application. Defined in this sectionPOST()Method to submit data, to get the value submitted by the form element for a detailed explanation.

Obtain the text box, password field, and button Value

Retrieving form data is actually obtaining data of different form elements. <Form> the name in the tag is an attribute of all form elements, that is, the name of the form element. You must use the name attribute to obtain the value Attribute value of the response. Therefore, all the added controls must define the corresponding name attribute value. In addition, do not repeat the control name to avoid data errors.

In the process of program development, the methods for obtaining the value of the text box, password domain, hidden domain, button, and text domain are the same, and the corresponding value attribute value is obtained using the name attribute. This section describes how to obtain form data by taking the data information in the text box as an example. I hope that my friends can try to obtain the values of other controls by themselves.

The following describes how to obtain text box information by using a logon instance. In the following instance, if you click "Log on", the user name and password are obtained.

The specific implementation steps are as follows:

(1) use any development tool to create a PHP dynamic page and name it index. php.

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

<! DOCTYPE html> 

(3) Add a PHP tag anywhere outside the <form> form element and use the if Condition Statement to determine whether the user has submitted the form. if the condition is true, use the echo statement to output the username and password obtained using the $ _ POST [] method. The Code is as follows:

<? Phpif ($ _ POST ["submit"] = "login ") {// determine whether the submitted button name is "Logon" // use the echo statement to output the username and password obtained using the $ _ POST [] method echo "username :". $ _ POST ['user']. "<br> password :". $ _ POST ['pwd'] ;}?>

Note: when using the text box to pass values, you must correctly set the name attribute of the text box, which should not contain spaces. When obtaining the value of the text box, the text box name must be the same as the name set in the form text box. Otherwise, the text box value cannot be obtained.

(4) enter the running address in the browser and press enter to obtain the running result as shown in:

The above is an example code for PHP to get the text box, password domain, and button value. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.