Content Column |
---|
width | 100.00002% |
---|
| Content Block |
---|
id | 111 |
---|
class | cef_menu_block |
---|
| 1145708437 |
---|
| HTML | <script type="text/javascript">
// Form Logic
// Form DOM present in .brikit.footer.cef
AJS.toInit( function ($) {
// Shows the dialog from url
if(window.location.hash) {
if(window.location.hash.substring(1) === "dialog-show-newsletter") {
AJS.dialog2("#newsletter-dialog").show();
ga('send', 'event', "Newsletter", "modal");
}
}
// Shows the dialog when the "Show dialog" button is clicked
$("#dialog-show-newsletter-cat").click(function(e) {
e.preventDefault();
AJS.dialog2("#newsletter-dialog").show();
ga('send', 'event', "Newsletter", "modal");
});
$("#dialog-show-newsletter").click(function(e) {
e.preventDefault();
AJS.dialog2("#newsletter-dialog").show();
ga('send', 'event', "Newsletter", "modal");
});
// Hides the dialog
$("#dialog-close-newsletter").click(function(e) {
e.preventDefault();
AJS.dialog2("#newsletter-dialog").hide();
});
// Form submission
var $form = $('form#newsletter');
if ( $form.length > 0 ) {
$('form#newsletter input[type="submit"]').bind('click', function (e) {
e.preventDefault();
if (validate_name()) {
if (validate_email()) {
register($('form#newsletter'));
} else {
var myFlag = AJS.flag({
type: 'error',
close: 'auto',
title: 'Error',
body: '<p>Please enter a valid email address.</p>'
});
}
} else {
var myFlag = AJS.flag({
type: 'error',
close: 'auto',
title: 'Error',
body: '<p>Please enter a valid name.</p>'
});
}
});
}
// Email check with regex
function validate_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($("#mce-EMAIL").val());
}
// Name check with value check
function validate_name() {
return $("#mce-NAME").val() != "";
}
// Register to mailchimp
function register($form) {
$.ajax({
type : 'GET',
url : 'https://europa.us13.list-manage.com/subscribe/post-json?u=9a428438959d4d20c2a84163b&&id=bc6ca47df5&c=?',
data : $form.serialize(),
cache : false,
dataType : 'json',
contentType : "application/json; charset=utf-8",
error : function(err) { alert("Could not connect to the registration server. Please try again later."); },
success : function(data) {
if (data.result != "success") {
var myFlag = AJS.flag({
type: 'error',
close: 'auto',
title: 'Error',
body: data.msg
});
} else {
AJS.dialog2("#newsletter-dialog").hide();
var myFlag = AJS.flag({
type: 'success',
close: 'auto',
title: 'Form Submitted',
body: '<p>Welcome to the CEFDIGITAL Newsletter, you will receive a confirmation email soon.</p>'
});
$( 'form#newsletter' ).each(function(){
this.reset();
});
ga('send', 'event', "Newsletter", "subscribed");
}
}
});
}
});
</script> |
|
|