I am adding the new user details to Constant Contact via their API when a user signs up. I am having problems with the plugin. I tried the below with both $NewUser[variable] and $user[variable]. Do you have any ideas on this?
I’ll donate via GPL a snippet I have for using Foxycart downloads on your own server if I can get some help with this.
Code:
$e = &$modx->Event;
switch ($e->name) {
case "OnWebSaveUser":
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
$cc_username = "CONSTANT_CONTACT_USERNAME";
$cc_password = "CONSTANT_CONTACT_PASSWORD";
$list_name = 'CONSTANT_CONTACT_EMAIL_LIST';
$cc_url = "CONSTANT_CONTACT_URL";
// Constant form data
$cc_data = "loginName=" . $cc_username;
$cc_data .= "&loginPassword=" . $cc_password;
$cc_data .= "&ea=" . urlencode(strip_tags($NewUser["email"]));;
if (isset($NewUser["first_name"])) $cc_data .= "&First_Name=" . urlencode(strip_tags($NewUser["first_name"]));
if (isset($NewUser["middle_name"])) $cc_data .= "&Middle_Name=" . urlencode(strip_tags($NewUser["middle_name"]));
if (isset($NewUser["last_name"])) $cc_data .= "&Last_Name=" . urlencode(strip_tags($NewUser["last_name"]));
if (isset($NewUser["title"])) $cc_data .= "&Job_Title=" . urlencode(strip_tags($NewUser["title"]));
if (isset($NewUser["Company_Name"])) $cc_data .= "&Company_Name=" . urlencode(strip_tags($NewUser["Company_Name"]));
if (isset($NewUser["Work_Phone"])) $cc_data .= "&Work_Phone=" . urlencode(strip_tags($NewUser["Work_Phone"]));
if (isset($NewUser["phone"])) $cc_data .= "&Home_Phone=" . urlencode(strip_tags($NewUser["phone"]));
if (isset($NewUser["address"])) $cc_data .= "&Address_Line_1=" . urlencode(strip_tags($NewUser["address"]));
if (isset($NewUser["Address_Line_2"])) $cc_data .= "&Address_Line_2=" . urlencode(strip_tags($NewUser["Address_Line_2"]));
if (isset($NewUser["Address_Line_3"])) $cc_data .= "&Address_Line_3=" . urlencode(strip_tags($NewUser["Address_Line_3"]));
if (isset($NewUser["city"])) $cc_data .= "&City=" . urlencode(strip_tags($NewUser["city"]));
if (isset($NewUser["state"])) $cc_data .= "&State=" . urlencode(strip_tags($NewUser["state"]));
if (isset($NewUser["country"])) $cc_data .= "&Country=" . urlencode(strip_tags($NewUser["country"]));
if (isset($NewUser["zip"])) $cc_data .= "&Postal_Code=" . urlencode(strip_tags($NewUser["zip"]));
if (isset($NewUser["Sub_Postal_Code"])) $cc_data .= "&Sub_Postal_Code=" . urlencode(strip_tags($NewUser["Sub_Postal_Code"]));
if (isset($NewUser["Email_Type"])) $cc_data .= "&Email_Type=" . urlencode(strip_tags($NewUser["Email_Type"]));
$list_data = "&ic=" . urlencode(strip_tags($list_name));
//If the form was submitted, and the email is valid, then POST via libcurl
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$cc_url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $cc_data . $list_data); // add POST fields
$cc_result = curl_exec($ch); // run the whole process
curl_close($ch);
break;
default :
return; // stop here - this is very important.
break;
}