Simple hosted sign up form for newsletter sign-up example

Participant

Simple hosted sign up form for newsletter sign-up example

Hello, I am new to Constant Contact as a whole, but I have a client that uses the service to send their newsletters. 

 

I am looking for a simple example form that I can use to replace an existing custom sign-up form. 

 

Really simple, just email, fname and lname. 

 

I assume that the there would be hidden fields where I would put their account/list IDs and a URL to POST to, but I can't find any documentation to support this threory. 

 

Can anyone point me int he right direction here? 

 

I don't have direct access to their account, but I am sure I can get any info I need from them if this is possible.

 

I saw the form generator PHP download, but that seems like overkill.

 

Thanks,

Jason 

1 REPLY 1
Employee

Hi Jason,

 

You can either use the Constant Contact Signup Form Generator (little to no coding required), or you can use the Formstack integration under Contacts>>Grow My Contact List>>Create a signup form (again, no coding, but you can make only limited changes to the appearance of the form), or create your own form using our sample code as a jumping off point.  Here is the PHP I use to add a contact to a list.  I do a check to see if the contact has already been in the account first, because it will result in an error if you try to add an existing contact.  The sample below uses our PHP wrapper located here.

 

<?php

session_start ();
require_once 'ConstantContact.php';
require_once 'config.php';

//$ConstantContact = new ConstantContact("oauth2", $apiKey, $username, $accessToken);  //OR
$ConstantContact = new ConstantContact("basic", $apiKey, $username, $password);
//Supply your credentials--API Key and other details--in config.php

// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50

// Email address here is used for testing purposes
$emailAddress = "test_12132012@example.com";

// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);

//Debugging
echo '<pre>';
print_r($ConstantContact);
echo '</pre>';
echo $emailAddress . "<br>";

// 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 list and add a new list to it as
	 // this request requires a PUT and will remove the lists
	 // as they are stored in an array
	 array_push($contactObj->lists, $lists['lists'][1]->id );
	 //array_push($contactObj->lists, $lists['lists'][18]->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 updated.");
}	

?>

 

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page