Apr 5th, 2013, 9:50 AM
(This post was last modified: Aug 22nd, 2013, 3:14 PM by michatmaster7.)
.
.
Note: This set of instructions does not use MailChimps double opt-in option. With a little research using the links provided at the end, I'm confident that someone will be able to implement that as an additional feature and post a reply here.
2013-08-22
UPDATE: I am still using Mail Chimp API v1.3.2 for this post.
UPDATE: Added "OPTIN_TIME" code. Added resource to bottom.
UPDATE: Added step 3a (to verify merge tags).
1) Download the proper API Wrapper for MailChimp.
For PHP forms, scroll to the PHP scetion of the following link and download MCAPI v{current}. Make sure you are using the most up-to-date version. I suggest putting this in a well-organized folder structure, so you'll understand what it is when you look at it next year.
(ie: Design Work\FormTools\MailChimp API Addition\MailChimp API Wrappers\MCAPI v1.3.2 (PHP)\PHP wrapper full\{extracted files})
MailChimp API Wrappers: http://apidocs.mailchimp.com/api/downloads/#php
2) Upload the MailChimp API to your web site.
In your web site structure, add a new directory inside the FormTools directory, called /mailchimp/. Upload the MCAPI.class.php file from Step 1 to this new directory.
(ie: path/to/formtools/mailchimp/MCAPI.class.php)
3) Add the MailChimp API code to your form.
I'm going to assume that you're using server-side (PHP) validation on your external form and that you already have a working form, so look for the following IF statement in your forms PHP:
.
Instructions for Integrated MailChimp Newsletter Signup to a FormTools Form
Note: This set of instructions does not use MailChimps double opt-in option. With a little research using the links provided at the end, I'm confident that someone will be able to implement that as an additional feature and post a reply here.
2013-08-22
UPDATE: I am still using Mail Chimp API v1.3.2 for this post.
UPDATE: Added "OPTIN_TIME" code. Added resource to bottom.
UPDATE: Added step 3a (to verify merge tags).
1) Download the proper API Wrapper for MailChimp.
For PHP forms, scroll to the PHP scetion of the following link and download MCAPI v{current}. Make sure you are using the most up-to-date version. I suggest putting this in a well-organized folder structure, so you'll understand what it is when you look at it next year.
(ie: Design Work\FormTools\MailChimp API Addition\MailChimp API Wrappers\MCAPI v1.3.2 (PHP)\PHP wrapper full\{extracted files})
MailChimp API Wrappers: http://apidocs.mailchimp.com/api/downloads/#php
2) Upload the MailChimp API to your web site.
In your web site structure, add a new directory inside the FormTools directory, called /mailchimp/. Upload the MCAPI.class.php file from Step 1 to this new directory.
(ie: path/to/formtools/mailchimp/MCAPI.class.php)
3) Add the MailChimp API code to your form.
I'm going to assume that you're using server-side (PHP) validation on your external form and that you already have a working form, so look for the following IF statement in your forms PHP:
PHP Code:
<?php
if (empty($errors))
{
$params = array(
"submit_button" => "submit", // Change to name attribute of submit button
"next_page" => "http://www.yourdomain.com/thanks.php",
"form_data" => $_POST,
"namespace" => "you-should-do-this", // http://docs.formtools.org/api/?page=namespaces
"finalize" => true
);
ft_api_process_form($params);
}
?>Now you're going to add the following chunk of code just above the line with "$params = array("
Note: make sure you read all the comments in this code. Update fields to match your own form field name attributes. The following is just an example.
PHP Code:
<?php
// SUBSCRIBE TO MAILING LIST OPTION - ADD TO MAILCHIMP USING API
if (!empty($_POST['newsletter_input_name_attribute']))
{
// Include Mailchimp API class
require_once('../formtools/mailchimp/MCAPI.class.php');
// Your API Key: http://admin.mailchimp.com/account/api/
$api = new MCAPI('Your-API-Key-Here');
// Your List Unique ID: http://admin.mailchimp.com/lists/ (Click "settings")
$list_id = "Your-List-ID-Here";
// Variables in your form that match up to variables on your subscriber
// list. You might have only a single 'name' field, no fields at all, or more
// fields that you want to sync up.
$optinTIME = date('Y-m-d H:i:s'); // Sample field - depends on your list, added 2013-08-22
$merge_vars = array(
'FNAME' => $_POST['first_name'],
'LNAME' => $_POST['last_name'],
'EMAIL' => $_POST['email_confirmation'],
'OPTIN_TIME' => $optinTIME, //Added 2013-08-22
'OPTIN_IP' => $_SERVER['REMOTE_ADDR'] //uses the user's IP address, but MC still says "you added this person"
);
// SUBSCRIBE TO LIST
if ( $api->listSubscribe($list_id, $_POST['email_confirmation'], $merge_vars) === true ){
$mailchimp_result = 'Success! Check your email to confirm sign up.';
} else {
$mailchimp_result = 'Error: ' . $api->errorMessage;
}
}
?>
