Hey guys I have a problem with one plugin. I am using this jquery form valdiation to validate my form, but if I have an AJAX call to submit the data then the validation is ignored. I tried setting a global variable and making a control statement at the AJAX call to stop of submitting it but when I did that the validation worked but it can't submit the data.
Validation
var isValid = 0;
$.validate({
form : '#comment-form',
onSuccess : function() {
isValid = 1;
return false;
},
validateOnBlur : false,
errorMessagePosition : 'top',
scrollToTopOnError : false,
});
AJAX Submit Data:
$(document).ready(function() {
if (isValid == 1)
{
$("#submitComment").click(function (e) {
e.preventDefault();
var name = $("#nameTxt").val();
var comment = $("#commentTxt").val(); //build a post data structure
var article = $("#articleID").val();
var isFill = $("#isFillTxt").val();
jQuery.ajax({
type: "POST", // Post / Get method
url: "<?php echo site_url('articles/create_comment/'); ?>", //Where form data is sent on submission
dataType:"text", // Data type, HTML, json etc.
data: "body=" + comment + "&name=" + name + "&article_id=" + article + "&isFillCheck=" + isFill, //Form variables
success:function(response){
$("#responds").append(response);
document.getElementById("commentTxt").value="";
document.getElementById("nameTxt").value="";
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
});
}
});