Edition:
After posting this answer, MailChimp released versions 2 and 3 of its API. Version 3 will be the only supported version starting in 2017. As soon as I have the opportunity to test it, I will update this answer for API version 3.
MailChimp API v3.0
According to the notice at the top of this page, all previous versions of the API will not be supported after 2016.
My solution uses PHP in the background to handle APIs and jQuery to facilitate Ajax.
1) Download a PHP shell that supports API v3.0. At the time of this writing, the latest MailChimp docs supporting v3.0 haven’t officially stated anything, but some of them are listed on GitHub, so I chose this one .
2) Create the following PHP file store-address.php using your own API key and list identifier, and then put it in the same directory as the wrapper from the first step. Remember to follow the documentation for your wrapper, but they all look pretty similar to this.
<?php
3) Create your HTML / CSS / JavaScript (jQuery) form (it’s not necessary that it be on the PHP page, and the visitor will never see that PHP is used in the background.)
The answer is in JSON, so you have to handle it correctly.
This is what my index.html file looks like:
<form id="signup" action="index.html" method="get"> First Name: <input type="text" name="fname" id="fname" /> Last Name: <input type="text" name="lname" id="lname" /> email Address (required): <input type="email" name="email" id="email" /> <input type="submit" id="SendButton" name="submit" value="Submit" /> </form> <div id="message"></div> <script src="jquery.min.js"></script> <script> $(document).ready(function() { $('#signup').submit(function() { $("#message").html("Adding your email address..."); $.ajax({ url: 'inc/store-address.php', </script>
MailChimp API version 1:
(original answer)
With a little work, I found a site using a PHP example with jQuery. From this, I was able to create a simple jQuery HTML page containing the main registration form. PHP files are “hidden” in the background when the user never sees them, but jQuery can still use and use.
1) Download the PHP 5 jQuery example here ... ( EDIT : links are dead. However, the only important part is the official PHP API shell available HERE .)
http://apidocs.mailchimp.com/downloads/mcapi-simple-subscribe-jquery.zip
If you have only PHP 4, just download MCAPI version 1.2 and replace the corresponding MCAPI.class.php file above.
http://apidocs.mailchimp.com/downloads/mailchimp-api-class-1-2.zip
2) Follow the instructions in the Readme file by adding your API key and list ID to the store-address.php in the appropriate places.
3) You may also want to collect a username and / or other information. You must add the array to the store-address.php file using the appropriate Merge variables.
This is what my store-address.php file looks like, where I also collect the first name, last name and email type:
<?php function storeAddress() { require_once('MCAPI.class.php');
4) Create your HTML / CSS / jQuery form. This does not have to be on a PHP page.
This is what my index.html file looks like:
<form id="signup" action="index.html" method="get"> First Name: <input type="text" name="fname" id="fname" /> Last Name: <input type="text" name="lname" id="lname" /> email Address (required): <input type="email" name="email" id="email" /> HTML: <input type="radio" name="emailtype" value="html" checked="checked" /> Text: <input type="radio" name="emailtype" value="text" /> <input type="submit" id="SendButton" name="submit" value="Submit" /> </form> <div id="message"></div> <script src="jquery.min.js"></script> <script> $(document).ready(function() { $('#signup').submit(function() { $("#message").html("Adding your email address..."); $.ajax({ url: 'inc/store-address.php', </script>
Required Fragments ...
index.html , built both above and similar. With jQuery, the look and feel are endless.
store-address.php file downloaded as part of the PHP examples at the Mailchimp website and modified using the KEY API and LIST ID . You need to add other additional fields to the array.
The MCAPI.class.php file downloaded from the Mailchimp website (version 1.3 for PHP 5 or version 1.2 for PHP 4). Put it in the same directory as your store-address.php , or you must update the url in store-address.php so that it can find it.