Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Created April 29, 2011 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebellacera/948916 to your computer and use it in GitHub Desktop.
Save jakebellacera/948916 to your computer and use it in GitHub Desktop.
A super advanced JS emailer. Uses the JQuery Validation plugin.
/**
* Mail.js 1.1
* ===========
* A simple AJAX emailer
*/
$(function(){
$('#mailform').validate({
// Set rules for special fields (email/phone)
rules: {
email: {
required: true,
email: true
}
},
submitHandler: function(form) {
// Create variables from form
var fname = $("input#fname").val();
var lname = $("input#lname").val();
var email = $("input#email").val();
var phone = $("input#phone").val();
// Who's dat?
var fullname = fname + ' ' + lname;
// Create variables that will be sent in a URL string to mail.php
var dataString = '&name=' + fullname + '&email=' + email + '&phone=' + phone;
// The AJAX
$.ajax({
type: "POST",
url: "/clients/ace_of_spades-fullsite/etc/mail.php",
data: dataString,
success: function() {
// AJAX output
$("#shadow").fadeIn();
$("#mailbox").fadeIn();
$(':input','#mailform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
return false;
}
});
return false;
}
});
$("#closebutton").click(function(){
$("#shadow").fadeOut();
$("#mailbox").fadeOut();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment