PHP implements getting the value of text box, password field and button

墨辰丷
Release: 2023-03-27 17:42:02
Original
3862 people have browsed it

This article mainly introduces the PHP example code for obtaining the value of the text box, password field, and button. Friends who need it can refer to it

Getting the value submitted by the form element is the most basic operation method in the form application . This section defines thePOST()method to submit data, and provides a detailed explanation of obtaining the value submitted by the form element.

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

Get the form data, actually get the different form elements data. The name in the

tag is an attribute that all form elements have, that is, the name of this form element. When using it, you need to use the name attribute to get the value attribute value of the response. Therefore, all controls added must define corresponding name attribute values. In addition, try not to repeat the naming of controls to avoid errors in the data obtained.

During the program development process, the methods for obtaining the values of text boxes, password fields, hidden fields, buttons and text fields are the same. They all use the name attribute to obtain the corresponding value attribute value. This section only takes obtaining the data information in the text box as an example to explain the method of obtaining form data. I hope friends can draw inferences from one example and try to obtain other control values by themselves.

The following uses a login example to learn how to obtain the information of the text box. In the example below, if the user clicks the "Login" button, the username 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:

    form 
用户名: 密 码:
Copy after login

(3) In< ;form>Add a PHP tag anywhere outside the form element, and use the if conditional statement to determine whether the user has submitted the form. If the condition is true, use the echo statement to output the user name and password obtained using the $_POST[] method. The code is as follows Reality:

密码为:" . $_POST['pwd']; } ?>
Copy after login

Note: When applying a text box to pass a value, be sure to set the name attribute of the text box correctly, and there should be no spaces; when getting When obtaining the value of a text box, the text box name used must be the same as the name set in the form text box, otherwise the value of the text box will not be obtained.

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

The above is the summary of this article All content, I hope it will be helpful to everyone's study.


Related recommendations:

Two implementation methods of php file upload_php skills

PHPArray function array_multisort() usage example analysis_php skills

##PHPFunction import_request_variables() usage analysis_ php skills

The above is the detailed content of PHP implements getting the value of text box, password field and button. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!