<form class="aui top-label" id="newsletter_cef">
<!-- Name -->
<div class="field-group">
<input class="text"
placeholder="Full Name"
type="text"
id="mce-NAME"
name="NAME"
data-aui-validation-required="required">
</div>
<!-- Email -->
<div class="field-group">
<input class="text"
placeholder="Email"
type="text"
id="mce-EMAIL"
name="EMAIL"
data-aui-validation-required="required">
<!-- Newsletter Group -->
<input type="checkbox"
value="70368744177664"
name="group[6381][70368744177664]"
id="mce-group[6381]-6381-46"
checked="checked"
style="display:none">
</div>
<div class="field-group">
<input class="button submit"
type="submit"
value="Subscribe">
</div>
</form>
<style>
#newsletter_cef input.submit {
border: none;
background-color: #FDD417 !important;
font-weight: bold;
text-shadow: none;
}
#newsletter_cef input.submit:hover {
background-color: #f8cc02 !important;
}
</style>
<script type="text/javascript">
// Form Logic
AJS.toInit( function ($) {
// Form submission
var $form_cef = $('form#newsletter_cef');
if ( $form_cef.length > 0 ) {
$('form#newsletter_cef input[type="submit"]').bind('click', function (e) {
e.preventDefault();
if (validate_name()) {
if (validate_email()) {
console.log($form_cef.serialize());
register($('form#newsletter_cef'));
} 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_cef) {
$.ajax({
type : 'GET',
url : 'https://europa.us13.list-manage.com/subscribe/post-json?u=9a428438959d4d20c2a84163b&&id=bc6ca47df5&c=?',
data : $form_cef.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_cef' ).each(function(){
this.reset();
});
ga('send', 'event', "Newsletter", "subscribed");
}
}
});
}
});
</script> |