The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Adding funcionality to the PHP auto generated form...

Highlighted
Occasional Contributor

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:

 

session_start();

$_SESSION

 

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?

1 REPLY 1
Highlighted
Employee

Re: Adding funcionality to the PHP auto generated form...

Hi,

 

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: http://community.constantcontact.com/t5/Documentation/API-Keys/ba-p/25015

 

2.  Download the wrapper here: https://github.com/constantcontact/ctct_php_library   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.

 

<html>
<body>
<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" />
</form>
</body>
</html>
<?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.

 

<?php

$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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured