Email subscription form - HTML

Participant

Email subscription form - HTML

Hi,

 

I am quite new to constant contact, just helping a colleague in a sister company as I handle the email in our company and have found it extremely diffiult to get a simple subscription form to be embedded, that can be styled to suit our site and layout requirements in a website based on asp.net, driven by a CRM.

 

I've achieved this quite simply before when using an alternative email marketing provider by calling in a 'stand alone' webpage (hosted on our webserver) via an iframe, which contains the "<FORM>" HTML and this continues to work extrememly well and allows full customisation of the style, with no thrid part branding!! I do not seem to be able to get this simple "<FORM>" code from CC and cannot think why, embedding  the forms with java script or iframes that point to the CC / formstack website is so inflexible in terms of styling.

 

There must be a simple solution to this, the process should be...

 

User enters data into a form embedded into our website, for that data to populate a specific contact list in CC, and return a 'thank you' type message. At no point should the user of our website leave that page, or know what is happening 'in the background'. Essentially this should be seamless.

 

If the above can be sorted I would be quite happy, however why it is also not possible to specify a seperate success / fail URL's allowing customisation of the message - the very restricted options such as "thank you" or "fail" are in my opinion promoting poor practice at best. If the form fails I would like to have a more in depth message to include e.g.  contact details of our office to keep the user happy

 

As I said I am new to CC, but not email and my experience thus far with this feature and other aspects has simply made me happy not to be with CC - please forum change my mind if you can as it seems very basic functionality is either just difficult to implement or lacking from CC.

 

Help!

 

Chris

 

 

 

1 REPLY 1
Employee

Hi,

 

Sorry you found some of our signup form solutions lacking.  You could use our SIgnup Form Generator, which requires little to no coding, or you could use our API to connect your form with us and use your existing formatting.  If you wish to do the latter, here are some steps to get you started.

 

Here is my example script and the steps to take to put 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 contents of the index.php file included in the wrapper with the following 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.

 

<html>
<body>
	<H1>Search for 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 = "";

$accessToken = ""; // needed for Oauth2

$apikey = "";

 

?>

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page