Sign up to {{custom.newsletter_auto_promote_name}} newsletter
{{custom.newsletter_auto_promote_description}}
Sign up to {{custom.newsletter_auto_promote_name}} newsletter
{{custom.newsletter_auto_promote_description}}
console.log('Piano: starting piano script');
$('.success').hide();
$('#error-placeholder').hide();
//regex to validate email (need to check with regex bods if this is a good pattern)
function validateEmail(email) {
console.log("Checking "+email);
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function sendMessageToMartini(email) {
if ($('#useremail').val()!=""){
var email = $('#useremail').val();
}
console.log('Piano: Sending to Martini with %s', email);
var newsletterId = $('#newsletterId').val();
console.log('Piano: Newsletter id %d', newsletterId);
var message = {src: 'sign-up', email: email, newsletter_id: newsletterId, template_id: "{{ params.templateId }}"};
window.parent.postMessage(message, '*');
$('.success').show();
$('.pn-offer-list__body').hide();
}
function setMartiniHandlers(emailInputID, formID, newsletterID) {
$(emailInputID).blur(function() {
var email = $(emailInputID).val();
if (validateEmail(email)) {
$(this).css('border', '1px solid green');
document.getElementById("error-placeholder").innerHTML = "";
// $('.pn-offer-list__body').hide();
} else {
$(this).css('border', '1px solid red');
}
});
$(formID).click(function() {
if ($(emailInputID).val() == '') {
$('#error-placeholder').show();
$(emailInputID).css('border', '1px solid red');
document.getElementById("error-placeholder").innerHTML = "Please enter a valid email address.";
return false;
}
if ($(emailInputID).val() != '') {
$('#error-placeholder').show();
var email = $(emailInputID).val();
if (!validateEmail(email)) {
document.getElementById("error-placeholder").innerHTML = "Please enter a valid email address.";
return false;
}
}
sendMessageToMartini(email);
});
$(newsletterID).click(function(e) {
e.preventDefault();
sendMessageToMartini('');
return false;
});
}
window.setTimeout(function() {
setMartiniHandlers('#email', '#submitForm', '#loggedIn');
}, 1000);