PHP Forms and User Input
Before introducing the form, let’s first understand the basic knowledge about the form:
1. Form Tag
10. Reset, the reset button is used to restore the initial state of the form
Definition:
Note: The reset button is a very commonly used function to restore the initial value of the form. The value attribute specifies the text on the button.
11. Submit, submit form button.
Definition:
Note: When When this button is clicked, the form is submitted to the specified page. This button can have a name attribute value. Generally, we provide the value of $_POST[‘submit’] on the server side to determine whether the current request comes from a form submission.
The above content introduces the content, functions and precautions contained in the form. Now we will learn the specific content of the form in detail.
The $_GET and $_POST variables in PHP are used to retrieve information from a form, such as user input.
PHP Form Processing
One very important thing to note is that when processing HTML forms, PHP can automatically turn form elements from the HTML page into For use by PHP scripts.
Example
The following example contains an HTML form with two input boxes and a submit button.
form.html file code is as follows:
php中文网(php.cn)
名字: 年龄:
When the user fills out the above form and clicks the submit button, the form data will be sent to the PHP file named "welcome.php" :
welcome.php file is as follows:
欢迎 ! 你的年龄是 岁。
The demo accessed through the browser is as follows:
We will explain the $_GET and $_POST variables in PHP in the next chapter.