What is the preferred method of handling duplicate contact errors?

Participant

What is the preferred method of handling duplicate contact errors?

What is the preferred method of handling "duplicate contact" errors?

 

My code:

 

 

session_start ();
require_once 'ccontact/ConstantContact.php';
require_once 'ccontact/config.php';
        
$ConstantContact = new ConstantContact ( "oauth2", $apikey, $username, $accessToken );

$ContactLists = $ConstantContact->getLists();

// echo print_r($ContactLists);




    if(isset($_POST['emailaddress'])){
    

    
            $Contact = new Contact();
            $Contact->emailAddress = $_POST['emailaddress'];
            $Contact->firstName = $_POST['firstname'];
            $Contact->lastName = $_POST['lastname'];
            $Contact->lists = $_POST['lists'];
            $NewContact = $ConstantContact->addContact($Contact);
            if($NewContact){
                echo "<script>alert('Congrats!  You are added to the mailing list.');</script>";
    
            }
        

        
        
        
    }

 

 

RIght now, this gets placed within the markup of my page, and I'd like to hide it and replace it with a nicer error message to the user:

 

Constant Contact HTTP Request Exception: Error 409: Email address _(myemail)_ is already a contact

Fatal error: Call to a member function Attributes() on a non-object in /data/14/1/78/53/1078053/user/1118909/htdocs/ccontact/Components.php on line 208

1 REPLY 1
Employee

Hi,

 

If you look a tthe sample code I posted on your other forum post here, I first search to see if the email address exists, then I add  a new contact if it doesn't, and update the existing contact if it does already exist in the account.  That's my preference.  However, you could also check to see if they exist (like I do), and then not update them and echo that they are already subscribed.

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page