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 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/customers/{username}/lists/6');
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.
David J
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/{username}/lists/6');
They appear to simply overwrite each other. When I print_r the $postFields I only get the last value.
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?
that worked. Thanks a lot for your help.
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article