Adding funcionality to the PHP auto generated form...

Regular Participant

Adding funcionality to the PHP auto generated form...

At the moment I am doing some code work inside of signup/index.php from the autogenerated form code. It seems that my calls to:





are being ignored by the program. Is there some settings for this? I have to synchronize with two databases so I need to capture the $postArray into the session. Has anyone done this successfully?




The CCSFG (Constant Contact SIgnup Form Generator) wasn't built with customizations in mind.  Most of the time when developers want to send the information to 2+ places they would use the main PHP wrapper and capture the email address (and any other details) and send it on appropriately.  You can certainly keep using the CCSFG, but I'm not aware of anyone who has used it to send information to their own databases in addition to ours.


If you want to use the main PHP wrapper, I can give you my example script and the steps to take to build a working signup form on your webpage.


1.  Generate an API Key here:


2.  Download the wrapper here:   Place the files from the wrapper in the folder/path on your server where you want the signup form to be.  Normally this is the same place where your index.html file currently lives.


3.  Replace the index.php file contents included in the wrapper with the below code.  Make any desired changes, like adding a first name input or changing the listID (list number) that you want people added to in your account.  In your case, add code to send the data to your databases.


<H1>Add/Update a contact</H1>
<form action="index.php" method="post">
<input type="text" name="emailAddress" maxlength="50"> 
<input type="submit" name="submit" value="Submit" />
<?php session_start (); require_once 'ConstantContact.php'; require_once 'config.php'; //$ConstantContact = new ConstantContact ( "oauth2", $apikey, $username, $accessToken ); //OAuth2 $ConstantContact = new ConstantContact('basic', $apikey, $username, $password); //basic authentication // Get potential contact lists $lists = $ConstantContact->getLists(); // Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50 //Map all form inputs here $emailAddress = $_POST["emailAddress"]; // 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 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; //Set the opt in source $contactObj->optInSource = "ACTION_BY_CONTACT"; // Create the Contact and DONE $Contact = $ConstantContact->addContact($contactObj); echo ("Contact added."); } // Otherwise we update our existing contact 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 lists and add a new list to it as array_push($contactObj->lists, $lists['lists'][1]->id ); //Set the opt in value $contactObj->optInSource = "ACTION_BY_CONTACT"; $contactObj->firstName = 'firstname'; $contactObj->lastName = 'CTCTlastname'; // Update the contact and DONE $UpdateContact = $ConstantContact->updateContact($contactObj); echo ("Contact " . $emailAddress . " updated."); } ?>



4.  Replace the contents of config.php with this, filling in your username, password, and API Key.



$username = "";
$password = ""; //needed for basic authentication
$accessToken = ""; //only needed for Oauth2
$apikey = "";




Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page