The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Adding/Updating Contacts

Highlighted
Developer

Adding/Updating Contacts

Hi All,

 

I am having difficulties integrating my php code with Joomla CMS add-on RS Form Pro.

 

Before I look into problems related to Joomla, I'd like to first confirm that my php code is correct.  As I am not an experienced PHP coder, can someone please take a look and let me know if my code is correct?

 

include_once(JPATH_SITE.DS.'components'.DS.'com_rsform'.DS.'helpers'.DS.'ConstantContact.php');

$username = 'sws-marketing';
$password = '<our password entered here>';
$apiKey = '<our api key entered here>';
$consumerSecret = '<our consumersecret code entered here';

$ConstantContact = new ConstantContact('basic', $apiKey, $username, $password);

$ContactLists = $ConstantContact->getLists();


$Contact = new Contact();
$Contact->emailAddress = $_POST['email'];
$Contact->firstName = $_POST['firstname'];
$Contact->lastName = $_POST['lastname'];
$Contact->lists[0] = 'http://api.constantcontact.com/ws/customers/sws-marketing/lists/383';


$emailAddress = $_POST['email'];

$search = $ConstantContact->searchContactsByEmail($emailAddress);

if($search == false)
{
$NewContact = $ConstantContact->addContact($Contact);
exit();



} // Otherwise we update our existing
else
{
//echo $Contact->emailAddress . " was added to your new list";
// Gather data from our previous search and store it into a data type
$Contact = $ConstantContact->getContactDetails($search[0]);

//print_r($Contact);
// We need to get the old list and add a new list to it as
// this request requires a PUT and will remove the lists
// as they are stored in an array
array_push($Contact->lists, 'http://api.constantcontact.com/ws/customers/sws-marketing/lists/383' );

// Update the contact and DONE
$UpdateContact = $ConstantContact->updateContact($Contact);
exit();
}

7 REPLIES 7
Highlighted
Moderator

Re: Adding/Updating Contacts

I will have one of our PHP support engineers look at this soon in detail to make sure everything is correct.  That said, the overall code does look correct to me without running it.

 

I have a question for you that may resolve this problem completely.  If you are using RSFormPro, they already integrate with Constant Contact to allow you to add email addresses from your RSFormPro form directly to your Constant Contact account.  Is there something you are looking to do that the integration doesn't allow you to do?  You can see in the plugins section on the RSFormPro website (http://www.rsjoomla.com/joomla-extensions/joomla-form.html) that they integrate with us directly.  If this doesn't support what you are looking to do, please let me know so I can pass the feedback on to them about a possible enhancement to the integration.

 

Also, for clarification when the engineer looks at your code, are you getting a specific error message that we should be looking at?  It's unclear from your description exactly what problem or error you're seeing which makes it hard for us to try to track down the cause.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Developer

Re: Adding/Updating Contacts

Thank you for the prompt reply! 

 

Yeah the ConstantContact plug-in for RS Form will not work for us because we eventually need to add the contact to the appropriate CC list based on a field value in the form (Product Name).  The RS Form plug-in doesn't allow for this.   Right now, my custom code (shown below) should do what the plug in does.  However, I eventually need to add the logic to the code so that it adds it to the appropriate CC list depending on the value in the Product Name field. 

 

Currently, if I use the script below, I get a white blank screen when I submit the form.  I checked the PHP log and there are no errors being logged...

Highlighted
Moderator

Re: Adding/Updating Contacts

Are you sure the update isn't happening?  From the code you pasted, nothing would show up on the page once the .php script finishes executing and would appear as a blank white page.  Since you don't check for success or failure and then redirect to a success/failure message page or load up something to show success/failure, I believe that the blank white page would indicate success.  If you could provide an email address that you've attempted to run this on in a private message to me, I'll take a look in your account to see if anything is happening.

 

I'll pass the feedback on to the developers over at RS as well just to let them know what you mentioned.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Developer

Re: Adding/Updating Contacts

Yes I just double checked.  The contacts are not being added to the list (383).   I recently tried to submit "johnsmith@123.com", and it wasn't added to the list. 

 

 

Highlighted
Moderator

Re: Adding/Updating Contacts

I looked at the logs for all of your API requests today and it looks like everything you've sent to us over the past 24 hours was successfully processed.  The confusing part of this is that every request you're sending to update a contact is being sent to update Contact ID 22948.  You've actually updated that contact successfully multiple times today including successfully adding that contact to List ID 383. 

 

My guess is that the email address you are searching for and updating is not the address you are expecting it to be.  Can you provide the code that is calling this PHP script so we can see how the POST parameter is being set?

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Developer

Re: Adding/Updating Contacts

Interesting.  I'm not sure where to grab the code from.  I've contacted the RS Joomla for some guidance.  Once I have it, I'll post it here. 

 

Thanks, 

Chris

Highlighted
Developer

Re: Adding/Updating Contacts

I think I figured it out.  

 

I was missing the ['form'] when assigning the $Constant array variables from the $_POST parameter.

 

$Contact = new Contact();
$Contact->emailAddress = $_POST['form']['email'];
$Contact->firstName = $_POST['form']['firstname'];
$Contact->lastName = $_POST['form']['lastname'];
$Contact->lists[0] = 'http://api.constantcontact.com/ws/customers/sws-marketing/lists/383';

 It looks like the contacts are now added to the list.  

 

I'm still getting a white screen after the form is submitted.  I will have to sort the rest out with RSJoomla.  But I think I'm good on this end now.  

 

Thanks for the help. 

 

Rgds,

Chris

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured