form submit in jquery validation code example
Example 1: submit ajax form validation jquery
$('#form').validate({
... your validation rules come here,
submitHandler: function(form) {
$.ajax({
url: form.action,
type: form.method,
data: $(form).serialize(),
success: function(response) {
$('#answers').html(response);
}
});
}
});
Example 2: jquery validation example
reference : https://www.sitepoint.com/basic-jquery-form-validation-tutorial/
$(function() {
$("form[name='registration']").validate({
rules: {
firstname: "required",
lastname: "required",
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
}
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
email: "Please enter a valid email address"
},
submitHandler: function(form) {
form.submit();
}
});
});
Example 3: jquery form validation
function submitFunction(event){
event.preventDefault();
}
$("#form_id").submit(submitFunction);