Last active
September 13, 2017 19:06
-
-
Save kgiszewski/6a4abf94e8d17fa369c855f5c73288f9 to your computer and use it in GitHub Desktop.
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 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; | |
} | |
}); |
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 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