I’m cranking on another project right now, so I can’t lay this out for you explicitly, but essentially, you’ll have a form that posts to a page that a call to the Campaign Monitor API. Just make sure you include the CMBase.php in your call. Here’s an example of the CM call:
<?php
//Sample using the CMBase.php wrapper to call Subscriber.AddWithCustomFields from any version of PHP
//Relative path to CMBase.php.
require_once('PHPWrapperSamples-1-1.3/CMBase.php');
$data['full_name'] = $_POST['full_name'];
$data['email'] = $_POST['email'];
$data['dob_yyyy'] = $_POST['dob_yyyy'];
$data['dob_mm'] = $_POST['dob_mm'];
$data['zip'] = $_POST['zip'];
$data['city'] = $_POST['city'];
$data['state'] = $_POST['state'];
$data['gender'] = $_POST['gender'];
//Your API Key. Go to http://www.campaignmonitor.com/api/required/ to see where to find this and other required keys
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$campaign_id = null;
$list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id );
send_one_to_cm($data, $cm);
//--------------------------------------------------------------------------
/* You have to set up custom fields on the campaignmonitor site in order for
this to work. The call should be formatted like this:
$result = $cm->subscriberAddWithCustomFields
($email, $full_name,
array(
'Genres' => array('comedy', 'mystery_suspense'), // Their API has trouble with &
'YearofBirth' => '1977', // 4 digit Number
'MonthofBirth' => '04', // two digit Number
'Zip' => '90042', // 5 digit Number
'City' => 'Los Angeles', // text
'State' => 'CA', // text abbrev.: CA, CO etc
'Gender' => 'Male', // Male | Female
)
);
When CM gets a post like this, the record is pretty much wiped clean and the
new values replace any existing ones. E.g. if a fan likes 2 genres and
wants to add a 3rd, you must send all 3. I.e. ANY info you include will
override whatever's in the db for this user.
*/
function send_one_to_cm($data, $cm) {
//This is the actual call to the method, passing email address, name and custom fields. Custom fields should be added as an array as shown here with the Interests and Dog fields.
//Multi-option field values are added as an array within this, as demonstrated for the Interests field.
// $result = $cm->subscriberAddWithCustomFields('[email protected]', 'Joe Smith', array('Interests' => array('Xbox', 'Basketball'), 'Dog' => 'Fido'));
$result = $cm->subscriberAddWithCustomFields
($data['email'], $data['full_name'],
array(
'YearofBirth' => $data['dob_yyyy'],
'MonthofBirth' => $data['dob_mm'],
'Zip' => $data['zip'],
'City' => $data['city'], // text
'State' => $data['state'], // text abbrev.: CA, CO etc
'Gender' => $data['gender'],
)
);
// Note: when you send this, ANY info you include will override whatever's in the db
// for this user.
if($result['Code'] == 0) {
echo "Success : ".$data['email']."\n";
} else {
echo 'Error : ' . $result['Message'] . "\n----------------------\n";
// Print out the debugging info
print_r($cm);
exit;
}
}
?>