Skip to content

Instantly share code, notes, and snippets.

@haydencarlson
Created April 8, 2018 22:59
Show Gist options
  • Save haydencarlson/fd3a9717df06cadc34bcde5ac8518c85 to your computer and use it in GitHub Desktop.
Save haydencarlson/fd3a9717df06cadc34bcde5ac8518c85 to your computer and use it in GitHub Desktop.
<style>
.formSuccess {
color: green;
}
.formError {
color: #bf0000;
}
</style>
<script type="text/javascript">
$(function() {
$('#send-contact-email').on('click', function(e) {
var formdata = $('#contacts').serialize();
$.ajax({
url: '{PATH_TO}/contact.php',
data: formdata,
method: 'POST'
}).then(function(response) {
console.log(response)
$('.contactFormMessage').removeClass("formSuccess");
$('.contactFormMessage').removeClass("formError");
var parsedResponse = JSON.parse(response);
$('.contactFormMessage').addClass(parsedResponse.style);
$('.contactFormMessage').text(parsedResponse.message);
});
});
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment