Last active
August 29, 2015 14:08
-
-
Save adamculpepper/9d14e717711eaccb8e62 to your computer and use it in GitHub Desktop.
AJAX form submission (using FormKeep & requires jQuery)
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
//Simple form | |
$("form").submit(function(e) { | |
e.preventDefault(); | |
$.ajax({ | |
type: 'POST', | |
url: 'https://formkeep.com/f/7212a0cb4563', | |
data: $(this).serialize(), | |
success: function() { | |
//window.location = "http://google.com"; | |
alert('Success!'); | |
}, | |
error: function() { | |
alert('Error!'); | |
} | |
}); | |
}); | |
// --------------------------------- | |
// A more advanced form, with success message | |
var form = $("form.ajax"); | |
form.submit(function(e) { | |
e.preventDefault(); | |
if ($("body").hasClass("support")) { | |
var formkeepID = "dd246894e127"; //support | |
var successMsg = "Thank you! We'll get back to you shortly."; | |
} else if ($("body").hasClass("partner-with-us")) { | |
var formkeepID = "f6b22efa1e43"; //partner-with-us | |
var successMsg = "Thank you! We'll get back to you shortly on partnering with us"; | |
} | |
$.ajax({ | |
type: 'POST', | |
url: 'https://formkeep.com/f/' + formkeepID, | |
data: $(this).serialize(), | |
success: function() { | |
form.find("input, button, textarea").prop('disabled', true).css({"opacity": 0.5}); | |
form.find(".alert-success").text(successMsg).fadeIn(500); | |
}, | |
error: function() { | |
alert('Error!'); | |
} | |
}); | |
}); |
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
<form> | |
<input type="text" name="name" placeholder="Your Name" required> | |
<input type="email" name="email" placeholder="Your Email" required> | |
<input type="submit" value="Submit"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment