Skip to content

Instantly share code, notes, and snippets.

Forked from mfkp/index.html
Created April 23, 2013 02:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ajax mailchimp signup form
<!DOCTYPE html>
<script type="text/javascript" src=""></script>
<script src="jquery.ketchup.all.min.js" type="text/javascript"></script>
<div id="email">
<span>Enter your email to sign up</span>
<form action="/subscribe.php" id="invite" method="POST">
<input type="text" placeholder="" name="email" id="address" data-validate="validate(required, email)"/>
<button type="submit">&#187;</button>
<span id="result"></span>
<script type="text/javascript">
$(document).ready(function() {
$('#invite').ketchup().submit(function() {
if ($(this).ketchup('isValid')) {
var action = $(this).attr('action');
url: action,
type: 'POST',
data: {
email: $('#address').attr('value')
success: function(data){
$('#result').html(data).css('color', 'green');
error: function() {
$('#result').html('Sorry, an error occurred.').css('color', 'red');
return false;
$apiKey = 'your-api-key';
$listId = 'your-list-id';
$email_type = 'html';
$email = $_POST['email'];
//replace us2 with your actual datacenter
$submit_url = "";
$data = array(
'id' => $listId,
'double_optin' => $double_optin,
'send_welcome' => $send_welcome,
'email_type' => $email_type
$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload));
$result = curl_exec($ch);
curl_close ($ch);
$data = json_decode($result);
if ($data->error){
echo $data->error;
} else {
echo "Got it, you've been added to our email list.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment