jQuery Validation with Joomla CMS
-
12-12-2019 - |
Question
I use below jquery.validation to validation email at the front-end. It works fine.
jQuery(function(){
//checking email is blank or not
jQuery("#email").validate({
expression: "if(VAL) return true; else return false;",
message: "<?php echo JText::_('Error in email'); ?>"
});
});
PHP - Joomla Save Button
JToolBarHelper::save();
I use joomla native save button to fire to save task in my controller.
HTML
<input type="text" name="email" id="email" value="">
My problem is jquery validation does not stop joomla submit. What I want to do is when user click SAVE I want to submit the form only if there are no validation error. How can I do it ? Thanks
Solution
May this will be helpful to you-
//Joomla 1.5
function submitbutton(pressbutton) {
var isValid = jQuery("#form-id").valid();
if(isValid){
submitform(pressbutton);
}else{
return false;
}
}
jQuery(document).ready(function(){
jQuery("#form-id").validate();
});
//joomla 2.5
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#form-id").validate();
});
Joomla.submitbutton = function(task)
{
var isValid = jQuery("#form-id").valid();
if(isValid){
Joomla.submitform(task, document.getElementById('form-id'));
}else{
return false;
}
}
</script>
for more details - http://docs.jquery.com/Plugins/Validation/valid
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow