- Constant Contact Community
- :
- Developer Community
- :
- Getting Started with API's
- :
- Re: Help with PHP add a contact...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Help with PHP add a contact...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-23-2011 02:25 PM
I am having some difficulty adding a contact using the php wrapper. I am not a professional programmer and am very new to this. We currently have formmail.php up and running and it seems to be pretty stable. I wanted to manipulate some of the hidden fields in our forms as well as determine whether or not the person filling out the form wished to be added to the mailing list before submitting data to formmail. I created a little file to do that for me. Both forms on the website submit data to this script called "submit.php". This works as long as the "mailing_list" checkbox is not checked.
Otherwise I get the error "This feed contains a DTD (Document Type Definition). DTDs are used to define a structure of a webpage. Internet Explorer does not support DTDs in feeds."
<?php
//Manipulate hidden fields for payment
if (isset($_POST["Registration_Selection"]) && $_POST["Registration_Selection"] == "Session 1 --- June 18 to June 23 2012 --- $325.00")
$_POST["Tuition"] = "325";
if (isset($_POST["Registration_Selection"]) && $_POST["Registration_Selection"] == "Session 2 --- June 25 to June 30 2012 --- $325.00")
$_POST["Tuition"] = "325";
if (isset($_POST["Registration_Selection"]) && $_POST["Registration_Selection"] == "Both Sessions --- June 18 to June 30 2012 --- $580.00")
$_POST["Tuition"] = "580";
$_POST["Process_Fee"] = "10";
//
//Check to see if they want to join the mailing list and if they do include the script to add the email address
//
if (isset($_POST["Mailing_List"]) && $_POST["Mailing_List"] == "Yes")
include('addcontact.php');
//
// Now include FormMail to do all the rest of the work...
//
include('formmail.php');
?> Here is the file "addcontact.php" that I am calling in the event that the checkbox is checked. I found this in another post and I am just trying to get this bit working before trying to add the rest of the contact info to the contact object from the POST array. I have place the php wrapper I downloaded into a folder called "ConstantConatct" and have removed my login info and key from the following.
<?php
include_once('ConstantContact/ConstantContact.php' );
// Connecting to your account
$ConstantContact = new ConstantContact("basic", "REMOVED", "REMOVED", "REMOVED");
// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50
// Email address here is used for testing purposes
// NOTE: This email address will be added to your account if you execute this script,
// you should send this to do-not-mail after your testing
$emailAddress = "testemail@test.com";
// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddr ess);
// If the search didnt return a contact object
if($search == false)
{
// Create a new Contact Object to store data into
$contactObj = new Contact();
// Adding multiple lists to this new Contact Object
$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
// Set the email address
$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'][3]->id );
// Update the contact and DONE
$UpdateContact = $ConstantContact->updateContact($contactObj);
}
?>
Any help would be greatly appreciated.
Re: Help with PHP add a contact...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-23-2011 03:58 PM
I tested the php code you provided that calls our API (using my own credentials, of course). It appears to be working for me, and it should work for your account as well, as long as you have a list 3 in your account.
The DTD error specifically is an issue outside of Constant Contact, where the internet browser may not have the functionality to process certain scripts. I know that is a major issue in Internet Explorer 7, so it would probably go away if you upgrade to IE8, or use another browser, like Firefox, Chrome, or Safari.
I hope that helps!
Re: Help with PHP add a contact...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-23-2011 07:00 PM
I changed the following line:
array_push($contactObj->lists, $lists['lists'][3]->id );
To:
array_push($contactObj->lists, $lists['lists'][0]->id, $lists['lists'][1]->id);
Because I do not have a list 3. Silly mistake. I do have a list 1 and 2. If I understand the code I am using correctly then
$lists['lists'][0]->id
refers to list number 1 and
$lists['lists'][1]->id)
refers to the next list.
I now get the following error:
"Constant Contact HTTP Request Exception: Error 400: Invalid data: State and country values do not match."
Now I am completely confused...
Re: Help with PHP add a contact...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-27-2011 07:30 AM
Hi,
That sounds like an issue with the XML that you are trying to pass into Constant Contact. Typical XML to your account should look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/user_name/contacts/1" rel="edit"></link>
<id>http://api.constantcontact.com/ws/customers/user_n
<title type="text">Contact: test@test.com</title>
<updated>2011-10-24T19:21:57.211Z</updated>
<author>
<name>Constant Contact</name>
</author>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/user_n
<Status>Active</Status>
<EmailAddress>test@test.com</EmailAddress>
<EmailType>HTML</EmailType>
<Name>Shannon W</Name>
<FirstName>Shannon</FirstName>
<MiddleName></MiddleName>
<LastName>W</LastName>
<JobTitle></JobTitle>
<CompanyName></CompanyName>
<HomePhone></HomePhone>
<WorkPhone></WorkPhone>
<Addr1></Addr1>
<Addr2></Addr2>
<Addr3></Addr3>
<City></City>
<StateCode></StateCode>
<StateName></StateName>
<CountryCode></CountryCode>
<CountryName></CountryName>
<PostalCode></PostalCode>
<SubPostalCode></SubPostalCode>
<Note></Note>
<CustomField1>custom input 1</CustomField1>
<CustomField2> </CustomField2>
<CustomField3></CustomField3>
<CustomField4> </CustomField4>
<CustomField5> </CustomField5>
<CustomField6></CustomField6>
<CustomField7></CustomField7>
<CustomField8></CustomField8>
<CustomField9></CustomField9>
<CustomField10></CustomField10>
<CustomField11></CustomField11>
<CustomField12></CustomField12>
<CustomField13></CustomField13>
<CustomField14></CustomField14>
<CustomField15></CustomField15>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/user_n
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/user_name/lists/3" rel="self"></link>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<OptInTime>2011-10-24T18:14:37.569Z</OptInTime>
</ContactList>
</ContactLists>
<Confirmed>true</Confirmed>
<InsertTime>2011-08-24T22:50:39.171Z</InsertTime>
<LastUpdateTime>2011-10-24T19:21:57.211Z</LastUpda
</Contact>
</content>
<source>
<id>http://api.constantcontact.com/ws/customers/user_n
<title type="text">Contacts for Customer: user_name</title>
<link href="contacts"></link>
<link href="contacts" rel="self"></link>
<author>
<name>user_name</name>
</author>
<updated>2011-11-09T23:17:10.620Z</updated>
</source>
</entry>
I would look at the XML that you are, in this instance, trying to pass into Constant Contact, and see if there is a discrepancy with the state and country you are trying to pass. They can be empty, so your first troubleshooting step should probably be to delete the content inside the state and country values, and try again. If that doesn't work, can you copy and paste your XML in your response?
Thanks,
Shannon W.
Constant Contact Support
Re: Help with PHP add a contact...
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-27-2011 08:10 AM
Hi Joshua,
I'm also wondering, what values are you attempting to pass through the StateCode and CountryCode?
Support Engineer
Re: Help with PHP add a contact...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-08-2012 09:32 AM
Hi all,
I'm also getting this error when using the PHP wrapper after retreiving a contact with getContactDetails and subsequently updating it with updateContact. The problem is that countryCode is " " after getContactDetails. Adding a trim countryCode solves the problem.
/Samuel Borgman


