Skip to content

Instantly share code, notes, and snippets.

@billrobbins
Created February 27, 2012 21:37
Show Gist options
  • Select an option

  • Save billrobbins/1927268 to your computer and use it in GitHub Desktop.

Select an option

Save billrobbins/1927268 to your computer and use it in GitHub Desktop.
Newsletter
<form id="signup" action="<?php echo get_permalink(); ?>" method="post">
<fieldset>
<span id="notification">
<?php
function storeAddress(){
if(!$_POST['email']){ return "Please enter a valid email address"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_POST['email'])) {
return "The email address is invalid";
}
require_once dirname( __FILE__ ) . '/mailchimp/MCAPI.class.php';
$mc_api = of_get_option('mc_api');
$api = new MCAPI('' . $mc_api . '');
$mc_list_id = of_get_option('mc_list_id');
$list_id = "$mc_list_id";
if($api->listSubscribe($list_id, $_POST['email'], '') === true) {
return 'It worked! Check your email to confirm your subscription';
}else{
return 'Error: ' . $api->errorMessage;
}
}
if($_POST['submit']){ echo storeAddress(); }
?>
</span>
<input class="email-subscribe" type="text" name="email" value="Your Email Address" onfocus="if (this.value == 'Your Email Address') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Your Email Address';}" />
<input type="submit" name="submit" value="<?php echo of_get_option('newsletter_button'); ?>" class="button" alt="Submit" />
</fieldset>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment