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.

Using hidden input to sign up to a specific email list.

Highlighted
Solution Provider

Using hidden input to sign up to a specific email list.

Hello,

 

I have this code that was migrated from an old website.  I need to add a hidden input field so that the users that sign up sign up for the right email list.  Below is my code.

 

<form name="ccoptin" action="http://visitor.constantcontact.com/d.jsp" target="_blank" method="post">
	<input type="text" name="ea" size="20" class="cc-input" value=""/>
	<input type="submit" name="go" value="Go" class="cc-submit"/>
	<input type="hidden" name="m" value="1105067396888"/>
	<input type="hidden" name="p" value="oi"/>
</form>

 Is this even possible?  Any help would be appriciated. 

 

Thanks,

1 REPLY 1
Highlighted
Employee

Re: Using hidden input to sign up to a specific email list.

Hi,

 

You can put a simple form like you have on your website to take an email address, and then subsequently send users to your Constant Contact-hosted registration form to complete being added to your account using the method I'm linking to here, but you can't do it all in one step on your website unless you use our Formstack integration or generate an API Key to use our API and write code to perform the contact addition.  Here is some sample PHP code that uses our PHP wrapper if you want to go the latter route.

 

<?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 = "testemail11192012@test.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;
	// 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 );
	
	// 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

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