Created
September 25, 2014 01:07
-
-
Save marcaum54/c1b5ed3525e7ab1edb30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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