PHP form validation


HTML Form Validation

When the form is used to collect customer input information, do not take it for granted that the customer will input the required content as expected. Customer input must be strictly checked at all times.

Client-side verification

Client-side form verification is generally a verification method based on Javascript scripts. This verification method can effectively reduce the burden on the server and can also instantly remind customers of input errors.

Server-side verification

In some cases, in addition to client-side verification, server-side verification may also be required (such as accessing the database). At this time, logical verification needs to be done in the PHP program.

We need to consider security when processing PHP forms.

In this chapter we will demonstrate the secure processing of PHP form data. In order to prevent hackers and spam, we need to perform data security verification on the form.

The HTML form introduced in this chapter contains the following input fields: required and optional text fields, radio buttons, and submit buttons:

form1.jpgView Code »

The above form validation rules are as follows:

FieldsValidation rules

#Name + Can only contain letters and spaces

E-mail + Must be a valid email address (contains '@' and '.')

URL Required. If present, it must contain a valid URL. Multi-line input field (text field)

Gender You must choose one

First let us look at the pure HTML form code:

Text field

The "Name", "E-mail", and "Website" fields are text input elements, and the "Remarks" field is a textarea. The HTML code is as follows:

"Name":
E-mail:
URL:
Remarks:

性别:

您输入的内容是:"; echo $name; echo "
"; echo $email; echo "
"; echo $website; echo "
"; echo $comment; echo "
"; echo $gender; ?>

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!