- Constant Contact Community
- :
- Developer Community
- :
- Getting Started with API's
- :
- PHP - add new contact
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
PHP - add new contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-19-2011 10:12 PM
Hi All
I'm trying to create a new contact - using a sample provided on the site (http://sourceforge.net/projects/ctctsampleforms/)
Here is my code:
<?php
include_once('cc_class.php');
$ccContactOBJ = new CC_Contact();
$ccListOBJ = new CC_List();
if (isset($_POST))
{
$postFields = array();
$postFields = $_POST;
$postFields = array(6);
$contactXML = $ccContactOBJ->createContactXML(null,$postFields);
if (!$ccContactOBJ->addSubscriber($contactXML)) {
echo $ccContactOBJ->lastError;
} else {
echo "Added";
}
}
else
{
?>
<form action="" method="post">
<input type="text" name="email_address">
<input type="submit" name="submit" value="submit">
</form>
<?php } ?>
When submit the form it comes back with message "An Error Occurred" - no more info about nature of the error.
I checked contact XML that gets sent to CC server - it seems to be ok and formed correctly. Login info is entered correctly as well - API key, u/p.
Any ideas what might be wrong? Any help will be much appreciated.
Vlad.
I believe the reason you are
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-20-2011 08:33 AM
I believe the reason you are seeing 'An Error Occurred’ is because you likely have $curl_debug set to false in cc_class.php line 29. If you set this to true it should return some more information about why this is failing to post.
I only needed to make one modification for this to create a new contact in my account, which was to change:
$postFields = array(6);
To:
$postFields = array('https://api.constantcontact.com/ws/customer
As the ‘lists’ needs to be an array of full list ID’s as opposed to just the actual id numbers. I believe the code below will work for you.
I hope this helps, please let me know if you have any other questions regarding this. Thanks.
include_once('cc_class.php');
$ccContactOBJ = new CC_Contact();
$ccListOBJ = new CC_List();
if (isset($_POST))
{
$postFields = array();
$postFields = $_POST;
$postFields = array('https://api.constantcontact.com/ws/customers/{use
$contactXML = $ccContactOBJ->createContactXML(null,$postFields);
if (!$ccContactOBJ->addSubscriber($contactXML)) {
echo $ccContactOBJ->lastError;
} else {
echo "Added";
}
}
else
{
?>
<form action="" method="post">
<input type="text" name="email_address">
<input type="submit" name="submit" value="submit">
</form>
<?php } ?>
David J
that worked. Thanks a lot for
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-20-2011 08:57 AM
that worked. Thanks a lot for your help.
Re: I believe the reason you are
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-03-2011 01:20 PM
I'm extremely confused here. I've been trying to work though this for a while, and I can't figure it out. Firstly, why would you write these statements?
$postFields = array();
$postFields = $_POST;
$postFields = array('https://api.constantcontact.com/ws/customers/{user
They appear to simply overwrite each other. When I print_r the $postFields I only get the last value.
Re: I believe the reason you are
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-04-2011 04:22 PM
Hey Julia,
I will look into this for you as I believe the idea was to have them append merge but that doesn't seem to be the case programmatically. I understand that syntax flaw but which area are you having trouble with?
Support Engineer, Constant Contact


