How to Use the built-in form verification function of joomla

Source: Internet
Author: User

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"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.