Skip to content

Instantly share code, notes, and snippets.

@kgiszewski
Last active September 13, 2017 19:06
Show Gist options
  • Save kgiszewski/6a4abf94e8d17fa369c855f5c73288f9 to your computer and use it in GitHub Desktop.
Save kgiszewski/6a4abf94e8d17fa369c855f5c73288f9 to your computer and use it in GitHub Desktop.
var registerHandleFormSubmit = function() {
$("#landingPage form").submit(function (e) {
e.preventDefault();
var $form = $(this);
var $email = $form.find(".email");
var $section = $form.closest("section");
var $thankYou = $section.find(".thank-you");
var $error = $section.find(".error");
resetForm($email, $error);
if (isValidateEmail($email)) {
var token = $('input[name="__RequestVerificationToken"]', $form).val();
$.ajax({
type: "POST",
url: "/umbraco/surface/subscribe/submit",
data: {
__RequestVerificationToken: token,
email: $email.val(),
listId: $form.data("list-id")
},
success: function (message) {
if (message.IsSuccess) {
handleSuccess($form, $thankYou, message);
} else {
handleFailure($form, $error, message);
}
},
error: function (e) {
console.log(e);
}
});
} else {
$email.addClass("error");
return false;
}
});
var handleSuccess = function ($form, $thankYou, message) {
$form.hide();
$thankYou.show();
}
var handleFailure = function ($form, $error, message) {
$error.text(message.ErrorMessage);
}
var resetForm = function ($email, $error) {
$email.removeClass("error");
$error.text("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment