The usage is as follows:
Enter the following code at the top of the page for using the form function:
JHTML: _ ('behavior. formvalidation ');
Add the following script to the page.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function formValidate (f ){
If (document. formvalidator. isValid (f )){
F. check. value = '<? Php echo JUtility: getToken () ;?> '; // Send token
Return true;
}
Else {
Alert ('some values are not acceptable. Please retry .');
}
Return false;
}
</Script>
Modify the code at the form Location
Copy codeThe Code is as follows: <form... onsubmit = "return formValidate (this)">
After the above Code is added, you only need to add class = "required" to the input in form, and the verification function will take effect.
The joomla verification script is implemented by class, and the class name determines the verification method used.
The most common class = "required" means mandatory
Class = "validate-email" indicates the verification email address.
The verification method can be used in combination. For example, if the Email is required and the format is correct, it can be written as follows:
Class = "validate-email required"
Custom verification method:
The Joomla verification function supports customization and allows you to set infrequently used verification rules.
For example, if I want to add a password item and a Confirm Password item, the two input boxes can only be submitted if the values are equal. You can add the following script
Copy codeThe Code is as follows:
Document. formvalidator. setHandler ('passverify ', function (value) {return ($ ('Password'). value = value );});
<Input type = "password" value = "" class = "validate-passverify"/>