We have improved this code again to join the form data verification function.
Usernamers must enter the username and password when logging in, and the username length cannot be less than three digits.
Form3.php
The output is as shown in the figure:
It can be seen that we only use the following three-line simple code to implement data verification, and more convenient compared to the methods we usually take.
// Add three verification rules $ form-> addrule ('name', 'username can't be empty!', 'Required'); $ form-> addrule ('name ",' username must be 3 or more letters or Number ',' minlength ', 3); $ form-> addrule (' password ',' password can't be empty! ',' Required ');
The four parameters of the addRule () method represent the object of the rule application, remind the text, and the type of verification rule (such as the request indicates that you must enter, you can't be empty), and verify the parameters of the rule. PEAR :: HTML_QUICKFORM comes with the verification rules as follows:
Rule name
parameter
Rule description
Required
Must enter, can not be empty
Maxlength
$ Length
Maximum character length
MINLENGTH
$ Length
Minimum character length
Rangelarth
$ MIN, $ MAX
Scope of character length
Regex
$ RX
The input data must match the given regular expression
True (Fordns Heck)
Verify the format of the email address (with an optional option, you can view the domain name is valid)
Lettersonly
Can only be English letters
Alphaumeric
Can only be English letters or numbers
Numeric
Can only be numbers
Nopunctuation
You cannot include the following special characters: (). / * ^? #! @ $% =, "'> <~ [] {}.
Nonzero
Can't be zero
Compare
Two inputs must be the same
Uploadedfile
Form elements must contain correctly upload files
MaxFilesize
$ SIZE
Maximum capacity for uploading files
MimeType
$ MIME
The type of upload file, $ mime can be an array, the type of uploaded file must be one
Filename
$ file_rx
The name of the uploaded file must meet a given regular expression
The Compare rules are a bit special, which refers to the input data of the two forms (such as password confirmation). Its usage is as follows:
$ form-> addelement ('password', 'password_1', 'enter your password:'); $ form-> addelement ('password', 'password_2', 'Enter Your Password (Again):'); $ FORM- > addrule (array ('password_1'), "Passwords Don't Match!", 'Compare');
Compare can also be used to compare the size of the data entered in both forms, such as:
$ form-> addelement ('text', 'min_age'); $ form-> addelement ('text', 'max_age', 'maximum age:'); $ form-> addrule (Array) 'min_age', 'Max_age'), "Minimum Age Must Be Less Than Maximum Age", 'Compare', '<');