[jQuery] using validate plugin in conjunction with form plugin (ajax submit)
I'm trying to submit a form via ajax using the form plugin, and also perform some validation, using the validate plugin. The problem I'm having is that when I submit the form, it performs the validation, but also submits it and returns the ajax response, regardless of the validation result... I need to figure out the proper coding so the submit only fires ifif it passes validation... Here's the code I have at this point, any suggestions is appreciated:
$().ready(function() {
$("#my_form").validate({
rules: { field_1: "required",
},
messages: {
field_1: "<span style='color:red;font-weight:bold'> required</span>",
}
});
});
$(document).ready(function() {
var options = {
target: '#response',
success: response
};
$('#my_form').ajaxForm(options);
});
function response(){
alert("The form has been submitted.");
}