Skip to content

Instantly share code, notes, and snippets.

@e-vural
Created July 10, 2015 11:06
Show Gist options
  • Save e-vural/86e99c6749df3568a002 to your computer and use it in GitHub Desktop.
Save e-vural/86e99c6749df3568a002 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$("form[name=myForm]").parsley();
$("form[name=myForm]").on('submit', function(e) {
var f = $(this);
f.parsley().validate();
if (f.parsley().isValid()) {
alert('This form is valid');
$.ajax({
url: f.attr('action'),
data: f.serialize(),
type: 'post',
dataType: 'json',
success: function(response) {
alert('Congrats! Your form was successfully submitted.');
},
error: function() {
alert('Crap! There was something wrong.');
}
});
} else {
alert('This form isn't valid');
}
e.preventDefault();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment