I’m building a MailChimp subscription form onto a site.
So I have a standard page template
that contains the snippet {sn_newsletter} that contains a simple form that submits to this template
<?php
function storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['email'])) {
return "Email address is invalid";
}
require_once($_SERVER['DOCUMENT_ROOT'] . '/mc/MCAPI.class.php');
// grab an API Key from <a href="http://admin.mailchimp.com/account/api/">http://admin.mailchimp.com/account/api/</a>
$api = new MCAPI('{lv_mailchimp_api_key}');
// grab your List's Unique Id by going to <a href="http://admin.mailchimp.com/lists/">http://admin.mailchimp.com/lists/</a>
// Click the "settings" link for the list - the Unique Id is at the bottom of that page.
$list_id = "{lv_mailchimp_id_{freebie_1}}";
//$list_id = "bfc533630f";
if($api->listSubscribe($list_id, $_GET['email'], '') === true) {
// It worked!
return 'Woohoo! You\'re now keeping current with happenings at Greenview';
} else {
// An error ocurred, return error message
return 'Error: ' . $api->errorMessage;
}
}
// If being called via ajax, autorun the function
if(isset($_GET['ajax'])) { echo storeAddress(); }
?>now if I hardcode the list id rather than call it from Low Variables, the form submits, if I use the Low Variable I get
Error: Invalid MailChimp List ID: bfc533630f
Any ideas?