Skip to content

Instantly share code, notes, and snippets.

@marcaum54
Created September 25, 2014 01:07
Show Gist options
  • Save marcaum54/c1b5ed3525e7ab1edb30 to your computer and use it in GitHub Desktop.
Save marcaum54/c1b5ed3525e7ab1edb30 to your computer and use it in GitHub Desktop.
$('#mc-form').validate({
highlight: function(element, errorClass) {
$(element).fadeOut(function() {
$(element).fadeIn();
});
},
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
message: {
required: true,
minlength: 10
}
},
messages: {
name: "<i class='fa fa-info-circle'></i>Please specify your name",
email: {
required: "<i class='fa fa-info-circle'></i>We need your email address to contact you",
email: "<i class='fa fa-info-circle'></i>Please enter a valid email address."
},
message: "<i class='fa fa-info-circle'></i>Please enter your message"
},
submitHandler: function(form) {
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
error: function(err) {
$('#mc-notification').hide().html('<span class="alert">Could not connect to server. Please try again later.</span>').fadeIn("slow");
},
success: function(data) {
if (data.result != "success") {
var message = data.msg.substring(4);
$('#mc-notification').hide().html('<span class="alert"><i class="fa fa-info-circle"></i>' + message + '</span>').fadeIn("slow");
$('#mc-form input[type="email"]').removeClass('success-input').addClass('error-input');
$('#mc-form input[type="nome"]').removeClass('success-input').addClass('error-input');
} else {
var message = data.msg.substring(4);
$('#mc-notification').hide().html('<span class="success"><i class="fa fa-paper-plane"></i>' + 'Awesome! We sent you a confirmation email.' + '</span>').fadeIn("slow");
$('#mc-form input[type="email"]').removeClass('error-input').addClass('success-input');
$('#mc-form input[type="nome"]').removeClass('error-input').addClass('success-input');
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment