Last active
August 29, 2015 14:18
-
-
Save gh-osh/1ca553f763dc3da2abe2 to your computer and use it in GitHub Desktop.
FormKeep + AJAX Submission + Success Message + URL Location
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 method="POST" class="ajax"> | |
<input type="text" name ="URL Location" id="urlLoc" style="display:none"> | |
<input type="text" name="name" placeholder="Your Name" required> | |
<input type="email" name="email" placeholder="Your Email" required> | |
<input type="submit" value="Submit"> | |
<div class="alert-success"></div> | |
</form> |
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
var elem = document.getElementById("urlLoc"); | |
elem.value = window.location.href; | |
var form = $("form.ajax"); | |
form.submit(function(e) { | |
e.preventDefault(); | |
var formkeepID = "00000000000"; //Insert FormKeep form ID | |
var successMsg = "Thank you! We'll get back to you shortly."; | |
$.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!'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment