Joomla's built in form validation function USES methods
- 2020-03-31 20:54:12
- OfStack
Here is how to use it:
Enter the following code at the top of the page where you want to use the form's functionality
JHTML: : _ (' behaviors. Formvalidation ');
Then add the following script to the page
Modify the code at the form location
After the above code has been added, validation will take effect as long as class="required" is added to the input in the form.
Joomla's validation scripts are implemented in class, and the name of the class determines which validation method is used.
The most common class="required" means required
Class ="validate-email" means validate the email address
Verification method can be used in combination. For example, I need Email to comply with the format before I can submit. I can write as follows:
Class = "validate - email required"
Customized verification method:
The Joomla validation feature supports customization, and you can set up validation rules that are not commonly used.
For example, I need to make a password item and a password item to confirm that the two input fields have the same value before I can submit. The following script can be added
Enter the following code at the top of the page where you want to use the form's functionality
JHTML: : _ (' behaviors. Formvalidation ');
Then add the following script to the page
<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
<form ... onsubmit="return formValidate(this)">
After the above code has been added, validation will take effect as long as class="required" is added to the input in the form.
Joomla's validation scripts are implemented in class, and the name of the class determines which validation method is used.
The most common class="required" means required
Class ="validate-email" means validate the email address
Verification method can be used in combination. For example, I need Email to comply with the format before I can submit. I can write as follows:
Class = "validate - email required"
Customized verification method:
The Joomla validation feature supports customization, and you can set up validation rules that are not commonly used.
For example, I need to make a password item and a password item to confirm that the two input fields have the same value before I can submit. The following script can be added
document.formvalidator.setHandler('passverify', function (value) { return ($('password').value == value); });
<input type="password" value="" class="validate-passverify" />