<?php
require dirname(__FILE__) . '/vendor/autoload.php';
$config = new MailWizzApi_Config(array(
'apiUrl' => 'https://www.pathlabtalk.net/newsletter/api',
'publicKey' => 'e9e421c1d09142691e0706679726c30e5c71a81c',
'privateKey' => '3a3c42bbe2b4dfda6bb0e02c2031c7a1335ca295',
));
// now inject the configuration and we are ready to make api calls
MailWizzApi_Base::setConfig($config);
// see if the request is made via ajax.
$isAjaxRequest = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
// and if it is and we have post values, then we can proceed in sending the subscriber.
if ($isAjaxRequest && !empty($_POST)) {
$lists = isset($_POST['lists']) ? (array)$_POST['lists'] : array();
foreach ( $lists as $list ) {
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->create($list, array(
'EMAIL' => isset($_POST['EMAIL']) ? $_POST['EMAIL'] : null,
'FNAME' => isset($_POST['FNAME']) ? $_POST['FNAME'] : null,
'LNAME' => isset($_POST['LNAME']) ? $_POST['LNAME'] : null,
));
}
exit(MailWizzApi_Json::encode(array(
'status' => 'success',
'message' => 'Thank you for joining our email list. Please confirm your email address now!'
)));
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Noto+Sans:700italic" />
<link rel="stylesheet" type="text/css" href="http://www.mailwizz.com/backend/assets/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="http://www.mailwizz.com/backend/assets/css/bootstrap-glyphicons.css" />
<link rel="stylesheet" type="text/css" href="http://www.mailwizz.com/backend/assets/css/style.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.mailwizz.com/backend/assets/js/bootstrap.js" id="script-bootstrap"></script>
<link rel="shortcut icon" href="http://www.mailwizz.com/favicon.ico" type="image/x-icon" />
<title>Ajax subscribe</title>
<style>
#content {
margin-top: 30px;
border: 1px solid #c2c2c2;
padding:10px;
}
div.error {
border: 1px solid #b94a48;
background: #f2dede;
color: #000000;
font-size: 12px;
padding:10px;
margin-bottom:10px;
}
div.success {
color: #000000;
background: #dff0d8;
border: 1px solid #d6e9c6;
font-size: 12px;
padding:10px;
margin-bottom:10px;
}
input.error {
border: 1px solid #b94a48;
background: #f2dede;
font-size: 12px;
}
</style>
<script>
jQuery(document).ready(function($){
// bootstrap button
$('.btn-submit').button();
$('#content form').on('submit', function(e){
e.preventDefault();
var $this = $(this);
var $message = $('.message');
var $email = $('input[name=EMAIL]', this);
// empty any previous message
$message.empty().removeClass('error').removeClass('success').hide();
// remove dinamically attached error elements
$('.error', $this).remove();
// just a small check, the api server will check anyway
var email = $email.val();
if (!email || email.indexOf('@') < 0) {
$message.addClass('error').text('Please enter a valid email!').show();
return false;
}
// show the loading text on the submit button
$('.btn-submit').button('loading');
// post the form to the php script and get the response
$.post('', $this.serialize(), function(json){
$('.btn-submit').button('reset');
$message.text(json.message).show();
// if the status is success, add the success class.
if (json.status == 'success') {
$message.addClass('success');
// also, empty the fields
$('input[type=text]', $this).val('');
} else {
// otherwise, add the error class.
$message.addClass('error');
}
}, 'json');
return false;
});
});
</script>
</head>
<body>
<div class="col-lg-4"><!-- --></div>
<div class="col-lg-4" id="content">
<!--
The form below is generated by MailWizz EMA.
You can see your list forms by viewing the "Embed forms" section of your email list.
-->
<div class="message"></div>
<form action="" method="post" accept-charset="utf-8" target="_blank">
<div class="form-group">
<label>Email <span class="required">*</span></label>
<input type="text" class="form-control" name="EMAIL" placeholder="" value="" required />
</div>
<div class="form-group">
<label>First name</label>
<input type="text" class="form-control" name="FNAME" placeholder="" value=""/>
</div>
<div class="form-group">
<label>Last name</label>
<input type="text" class="form-control" name="LNAME" placeholder="" value=""/>
</div>
<div class="form-group">
<label>Lists (ctrl + click / cmd + click to select multiple lists) </label>
<select multiple name="lists" class="form-control">
<option value="key"> List 1 </option>
<option value="key"> List 2 </option>
<option value="key"> List 3 </option>
<option value="key"> List 4 </option>
<option value="key"> List 5 </option>
</select>
</div>
<div class="clearfix"><!-- --></div>
<div class="actions">
<button type="submit" class="btn btn-default btn-submit" data-loading-text="Please wait...">Subscribe</button>
</div>
<div class="clearfix"><!-- --></div>
</form>
</div>
<div class="col-lg-4"><!-- --></div>
</body>
</html>