PHP forms and user input

We learned from the previous PHP basic tutorial that the $_GET and $_POST variables are used to retrieve information in the form, such as user input

So what is a form?

#The function of the Web form is to provide an interactive platform for viewers and the website. Forms are mainly used to send data to the server in web pages. For example, your registration information is the form you use. When you fill in the information, you have to submit. Submit is to transfer the content in your form from the client browser. It is transmitted to the server, and after being processed by the PHP program, the information required by the user is passed back to the client browser. By obtaining the user's information, PHP interacts with the Web form.

Note: Forms belong to HTML knowledge and will be explained in detail in our HTML tutorial


Let’s take a look at what the form looks like, shall we?

Example

    PHP中文网 
名字:
年龄:

The result of running the above code is as follows:

7.png

Yes, this is We are talking about forms, so where do we send the completed form information? When we click submit, the data in our form will be in the form of POST. Sent to the form.php page.

"; echo "你的年龄是:".$_POST['age']; ?>

The running results we sent to form.php:

Welcome: liuqi
Yours Age is: 18

##Form validation

should be in Validate user input whenever possible (via client script). Browser validation is faster and reduces the load on the server.

If user input needs to be inserted into the database, you should consider using server validation. A good way to validate a form on the server is to pass the form to itself, rather than jumping to a different page. This way users can get error messages on the same form page. It will be easier for users to find errors.

Let’s talk about our form validation in the next section



##

Continuing Learning
||
PHP中文网
名字:
年龄:
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!