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 other parameters to contact object

Highlighted
Occasional Contributor

Adding other parameters to contact object

I am having trouble getting the first name, last name, and phone number transferred from our web forms to CC.  The code I am using is below.  The email address is successful but the other info is left out.  Any help would be appreciated.

 

// Check to see which form this came from and assign the POST variable to a local variable

//MCS Registrations First
if (isset($_POST["this_form"]) && $_POST["this_form"] == "http://www.swcdi.org/MCS-Reg-1.htm")
{
$firstName = $_POST["Contact_First_Name"];
$lastName = $_POST["Contact_Last_Name"];
$homePhone = $_POST["Emergency_Phone"];
$emailAddress = $_POST["Email_Address"];
}

//Now do the "contact us" form
if (isset($_POST["this_form"]) && $_POST["this_form"] == "http://www.swcdi.org/contact.htm")
{
$firstName = $_POST["First_Name"];
$lastName = $_POST["Last_Name"];
$homePhone = $_POST["eve_phone"];
$emailAddress = $_POST["email_address"];
}

// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);

// If the search didnt return a contact object...
if($search == false)
{
// Create a new Contact Object to store data into
$contactObj = new Contact();
// Adding lists to this new Contact Object
$contactObj->lists = array($lists['lists'][0]->id);
// Set the properties for the contact object
$contactObj->firstName = $firstName;
$contactObj->lastName = $lastName;
$contactObj->homePhone = $homePhone;
$contactObj->emailAddress = $emailAddress;
// Create the Contact and DONE
$Contact = $ConstantContact->addContact($contactObj);
}

// Otherwise we update our existing
else 
{
// Gather data from our previous search and store it into a data type
$contactObj = $ConstantContact->getContactDetails($search[0]);
// 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($contactObj->lists, $lists['lists'][0]->id );

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

 

6 REPLIES 6
Highlighted
Moderator

Re: Adding other parameters to contact object

Hey Joshua,

 

I'm not seeing any immediate issues with how you're using the wrapper. I would be interested if we could get the value of $firstName before sending it through the function, either by echoing or checking if it is empty. Just as a quick example:

if(empty($firstName)) {
die();
} else {
echo $firstName;
}

 If we can see the value that's trying to go through, we can definitely test some things out with it.

Nick Galbraith
Support Engineer
Highlighted
Occasional Contributor

Re: Adding other parameters to contact object

I just ran that bit of code you suggested to test if a value was transferred from the POST array to the local variable $firstName.  It completed and returned the appropriate value.

 

Just for fun I checked the values of the other local variables and they all returned correct values.

 

It must be somewhere with how I am assigning those variables to the parameters of the new contact object.  Thoughts?

Highlighted
Occasional Contributor

Re: Adding other parameters to contact object

Any thoughts...I still can't get this working.  The email goes through just fine bu the additional information does not show up in the contact.

Highlighted
Moderator

Re: Adding other parameters to contact object

Hey Joshua,

 

I'd be interested in seeing the contact details of an email address before you pass it through this form. Are you using a completely new contact to the account? A removed contact would also retain some information, so the best troubleshooting step I can think of at this point (unless the contacts you are pushing through the form are already fresh to the account) would be to send through a completely fresh entry, and see if you get the same results.

 

Depending on the outcome of that test, I might just ask you to zip up your files and email them to us, so I can do the testing with the same environment you're working in.

Nick Galbraith
Support Engineer
Highlighted
Occasional Contributor

Re: Adding other parameters to contact object

Yes..even with a completely fresh contact the email adds correctly but the rest of the info is lost.

Highlighted
Moderator

Re: Adding other parameters to contact object

I'd love to get a look at your files to troubleshoot the problem. Would you be able to zip up your files and email them to webservices@constantcontact.com? We can take a look though and test the same code on our end to figure out the results.
Nick Galbraith
Support Engineer
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