I am trying to validate my form before the inputs will be processed and stored in the database. I used the jquery plugin for validation.
Here is my code for the validation:
$(document).ready(function(e) {
var container = $('div#error');
// validate the form when it is submitted
var validator = $("#my_form").validate({
errorContainer: container,
errorLabelContainer: $("ol", container),
wrapper: 'li',
meta: "validate"
});
$('#submit').click(function () {
$('body,html').animate({
scrollTop: 0
}, 800);
});
});
My form looks like this:
<form id="my_form" method="post" action="#">
<input class="{validate:{required:true}}" type="text" name="name" />
<input class="{validate:{required:true}}" type="text" name="age" />
<input type="submit" />
</form>
Now, I was wondering if how can I proceed to submit the form after the validation. I am planning to make an AJAX call after it.
Any help would be appreciated. Thanks!
You need to use
submitHandlerof thejQuery.validateoptions to do something like that. Please review the docs: http://docs.jquery.com/Plugins/Validation/validate#options