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:
View Code »
The above form validation rules are as follows:
FieldsValidation rules
#Name + Can only contain letters and spaces
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:
Radio button
The "Gender" field is a radio button, the HTML code is as follows:
HTML form code is as follows: