Create a signup form that limits user to one list

Occasional Participant

Create a signup form that limits user to one list

Hi, I'm new to constant contact, and have been looking for an example of code that would allow me to create a signup form that limits the user to one list. Currently my client has created a number of lists which are available for signup on from the main website (http://www.collectiveeye.org - the 'email list' link), but we are creating a separate website for a film that is in development that we would like to have a newsletter for, and just limit them to one specific list (and not have this 'general list' and other lists available - that is here - http://www.collectiveeye.org/queen/newsletter.html ).

Sounds simple, but I just can't find anything. Apologies if this has been discussed -- I've searched, but may not have the right terminology to find it..

cheers,

barry
32 REPLIES 32
Moderator

Hi Barry,

What you're looking to do is something the API is able to do. The problem I think you're running into is that the API is just the interface, it needs to be programmed into a server or client script in order to be used to do what you want to. There is a php example here that does basically what you're looking to do. You can use that as a starting point if you're familiar with php and modify it as you need or use it as a guide for how to accomplish what you're looking to if you use a different language.
Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

Great, thanks!

I was able to use this script, but I do have a question. The user is not sent an opt-in message to validate the email address using this form. We want to make sure people aren't signed up who don't want to be signed up, of course, and I imagine the opt-in method is Constant Contact's preferred way of having people sign up for lists. Is there a way to do this.

I will also be checking on the forum for making the form check for a valid email address..
Moderator

Hi Barry,

All you need to do to have the Opt In emails automatically sent is to turn on Confirmed Opt In for your Constant Contact account. You can do this in the My Settings tab.
Dave Berard
Senior Product Manager, Constant Contact
Regular Participant

 This thread is similar my question -- I want the user to see different lists chosen by default depending on which form they use (different forms on different sections of the site).


The link given - here - doesn't seem to have any information on that page.


Is there a hidden field that can be included in the form with some kind of code that determines which list the user will see chosen by default?


Thanks,


=vg

Regular Participant

This should be fairly easy to do, you just need to manually add the contact lists to a drop down or could even subscribe them automatically without giving a list selection.

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Regular Participant

Hi James, 


Could you please explain this a different way--not really following you.  I too want to create an opt-in box that goes to a specific list.  Thanks!

Anonymous
Not applicable

Hi,


That link no longer works because we have new samples that allow you to do what you want.


You can find the new sample code at http://developer.constantcontact.com/samples/upload_forms


and if you look at the documentation for the PHP sample to customize which lists you want people to subscribe to.

Regular Participant

Hi,


 Mr. Chang Suh.....Can you Pls reply for 2nd forum question (how to update State code in constant contact)


 


thanks,


satish


 

Regular Participant

Hi,


I looked thru the above link--thank you for that.  But I do not see how to do what this thread is asking.  Creating sign-up box that goes to one specific list.  Please help!!


 


 

Regular Participant

He just gave you a link to the sample forms, if you understand PHP or .NET you'll be able to modify those samples to do what you need really quickly.


See add_contact.php lines 195 - 215


That contains the list selection code, all you need to do is hide that bit then add a hidden form field here with the contact list ID of the list you want to subscribe your users to.


Hope that helps.

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Regular Participant

James, we are not tech-guys, I wish i was.  I need a step-by step way to do this.  For example: whats a hidden form field!  Just need: A B C D.  Thanks for your patience.


 

Regular Participant

Hi,


You can add a simple signup form with (or possibly without) a list selection to your website using your constant contact account,  it's a simple job of copying and pasting some code, however if you need certain functionality you cannot get using this method you need to use the API.


Sorry maybe I misunderstood, if your looking for a custom signup form that uses the API and do not have any programming experience of any sort you will need someone to do it for you.

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Regular Participant

 I do understand HTML and PHP -- the examples were of no use. 


Here's the problem -- I go to the signup form wizard, and Step 1 allows me to choose the style of form. Step 2 allows me to edit fonts and colors. Step 3 gives me the HTML code. I don't see anything else.


How -- please! -- do I get the form to target one particular list. As it stands, I can choose which lists show up when the user submits the form and gets to the CC website via the "Edit Your Join My Mailing List Form" page under "Lists", and which list is chosen by default. But these are global choices. I want my user to see a different list checked, depending on which of my forms they have submitted.


Surely there has to be a simple answer to this question. A hidden field perhaps, but how to know what the value of the field should be?


Thanks,


=vg

Regular Participant

You will need to use the API and a custom signup form to do this.


I've edited the add_contact.php example and posted it below, this should do what you need I think?


All you need to do here is edit line 191 and change YOUR_CONTACT_LIST_ID to the ID of your own contact list.


<?php



include_once('cc_class.php');







$ccOBJ = new ConstantContact();











/**



 * If we have post fields means that the form have been submitted.



 * Therefore we start submiting inserted data to ConstantContact Server.



 */



if (!empty($_POST)) {



    $postFields = array();







    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields= $_POST;   



       



    $postFields = $_POST;



    $postFields = $_POST;



   



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;  // The Code is looking for a State Code For Example TX instead of Texas



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;



    $postFields = $_POST;   



    $postFields = $_POST;



    $postFields = $_POST;   



   



    $postFields = $_POST;







    $postFields = array();



    foreach($_POST as $key=>$val) {



        if (strncmp($key, 'custom_field_', strlen('custom_field_')) === 0) {



            $postFields = $val;



        }



    }



   



   



    $contactXML = $ccOBJ->createContactXML(null,$postFields);



   



       



    if (!$ccOBJ->addSubscriber($contactXML)) {



        $error = true;



    }



    else {



        $error = false;



        $_POST = array();       



    }



   



}















//get all available lists for the current CC account.



$allLists = $ccOBJ->getLists();



//get all available states



$allStates = $ccOBJ->getStates();



//get all available countries



$allCountries = $ccOBJ->getCountries();







?>











<?php include_once('header.php');?>







<div align="center" style="width: 900px;">



<h2>Add a new Subscriber - Full form</h2>



<?php



//



// Here we add an area where messages  are displayed (error or success messages).



//



    if (isset($error)) {



        if ($error === true) {



            $class = "error";



            $message = $ccOBJ->lastError;    



        }



        else {



            $class = "success";



            $message = "Contact ".$_POST." Added.";



        }



        echo '<div class="'.$class.'">';



        echo $message;



        echo '</div>';



    }



?>







<form action="" method="post">



<div style="float: right; text-align: left; overflow: auto; height: 640px; width:250px;">



<input type="hidden" name="lists[]" value="YOUR_CONTACT_LIST_ID" />

<!--

    <fieldset>



        <legend> Interests list </legend>



    <?php



        foreach ($allLists as $k=>$item) {



            $checked = '';   



            if($_POST){



            if (in_array($item,$_POST)) {



                $checked = ' checked ';



            }



            }



            echo '<input type="checkbox" '.$checked.' class="checkbox" name="lists[]" value="'.$item.'" id="chk_'.$k.'" /> <label for="chk_'.$k.'">'.$item.'</label><br/>';



        }



    ?>       



    </fieldset>

-->



</div>   



<div>







    <h3>Contact information</h3>   



    <table width="580" border="0" cellpadding="2" cellspacing="0">



        <tr>



            <td align="left">Email Address:</td>



            <td align="left"><input type="text" name="email_address" value="<?php echo $_POST?>" maxLength="100" /></td>



            <td align="left">&nbsp;</td>



              <td align="left">&nbsp;</td>



      </tr>



        <tr>



            <td align="left">First Name:</td>



            <td align="left"><input type="text" name="first_name" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Last Name:</td>



            <td align="left"><input type="text" name="last_name" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Middle Name:</td>



            <td align="left"><input type="text" name="middle_name" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Home phone:</td>



            <td align="left"><input type="text" name="home_num" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left" valign="top">Address:</td>



            <td align="left" colspan="3">



                <input type="text" name="adr_1" maxLength="100" style="width: 440px"  value="<?php echo $_POST?>" /><br/>



                <input type="text" name="adr_2" maxLength="100" style="width: 440px" value="<?php echo $_POST?>" /><br/>



                <input type="text" name="adr_3" maxLength="100" style="width: 440px" value="<?php echo $_POST?>" /><br/>



            </td>



        </tr>



        <tr>



            <td align="left">City:</td>



            <td align="left"><input type="text" name="city" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">State:</td>



            <td align="left">



                <select name="state">



                <option value="">&nbsp;</option>



                <?php                



                foreach ($allStates as $stateCode=>$stateName) {



                    $selected = '';



                    if ($stateCode == $_POST) {



                        $selected = ' selected ';



                    }



                    echo '<option value="'.$stateCode.'" '.$selected.'>'.$stateName.'</option>';



                }



                ?>



                </select>



            </td>



        </tr>



        <tr>



            <td align="left">Zip:</td>



            <td align="left"><input type="text" name="postal_code" maxLength="100" value="<?php echo $_POST?>"/></td>



            <td align="left">State (Other):</td>



            <td align="left"><input type="text" name="state_name" maxLength="100" value="<?php echo $_POST?>"/></td>



        </tr>



        <tr>



            <td align="left">Sub-zip:</td>



            <td align="left"><input type="text" name="sub_postal" maxLength="100" value="<?php echo $_POST?>"/></td>



            <td align="left">Country:</td>



            <td align="left">



            <select name="country" maxLength="100">



                <option value="">&nbsp;</option>



            <?php



                foreach ($allCountries as $countryCode=>$countryName) {



                    $selected = '';



                    if ($countryCode == $_POST) {



                        $selected = ' selected ';



                    }



                    echo '<option value="'.$countryCode.'" '.$selected.'>'.$countryName.'</option>';   



                }



            ?>



            </select>



            </td>



            <td colspan="2"></td>



        </tr>



        <tr>



            <td align="left">E-Mail Type:</td>



            <td align="left" colspan="3">



                <input type="radio" class="checkbox" name="mail_type" id="mt1" value="HTML" <?php echo ($_POST=='HTML' || empty($_POST))?' checked ':'';?> />



                <label for="mt1">HTML</label>



                &nbsp;or&nbsp;



                <input type="radio" class="checkbox" name="mail_type" id="mt2" value="Text" <?php echo ($_POST=='Text')?' checked ':'';?> />



                <label for="mt2">Text</label>



            </td>           



        </tr>



    </table>



           



    <h3>Work details</h3>



    <table width="580" border="0" cellpadding="2" cellspacing="0">



        <tr>



            <td align="left">Company Name:</td>



            <td align="left"><input type="text" name="company_name" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Job Title:</td>



            <td align="left"><input type="text" name="job_title" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Work phone:</td>



            <td align="left"><input type="text" name="wrk_num" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td colspan="2"></td>



        </tr>



    </table>



    <h3>Custom Fields & Notes</h3>



    <table width="580" border="0" cellpadding="2" cellspacing="0">



        <tr>



            <td align="left">Custom Field 1:</td>



            <td align="left"><input type="text" name="custom_field_1" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 2:</td>



            <td align="left"><input type="text" name="custom_field_2" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 3:</td>



            <td align="left"><input type="text" name="custom_field_3" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 4:</td>



            <td align="left"><input type="text" name="custom_field_4" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 5:</td>



            <td align="left"><input type="text" name="custom_field_5" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 6:</td>



            <td align="left"><input type="text" name="custom_field_6" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 7:</td>



            <td align="left"><input type="text" name="custom_field_7" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 8:</td>



            <td align="left"><input type="text" name="custom_field_8" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 9:</td>



            <td align="left"><input type="text" name="custom_field_9" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 10:</td>



            <td align="left"><input type="text" name="custom_field_10" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 11:</td>



            <td align="left"><input type="text" name="custom_field_11" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 12:</td>



            <td align="left"><input type="text" name="custom_field_12" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 13:</td>



            <td align="left"><input type="text" name="custom_field_13" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left">Custom Field 14:</td>



            <td align="left"><input type="text" name="custom_field_14" maxLength="100"  value="<?php echo $_POST?>" /></td>



        </tr>



        <tr>



            <td align="left">Custom Field 15:</td>



            <td align="left"><input type="text" name="custom_field_15" maxLength="100"  value="<?php echo $_POST?>" /></td>



            <td align="left"></td>



            <td align="left"></td>



        </tr>



        <tr>



            <td align="left">Notes:</td>



            <td align="left" colspan="3">



            <textarea rows="8" cols="50" name="notes"><?php echo htmlspecialchars($_POST)?></textarea>



            </td>



        </tr>



        <tr>



            <td align="center" colspan="4">                 



                <input type="submit" name="submit" value="Add Contact" />



            </td>



        </tr>



    </table>



</div>



</form>



</div>


 

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Regular Participant

@Please start your own forum post to ask a question as your question is different your just confusing things, thanks.

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Occasional Participant

 


 


 

Pamela

Occasional Participant

I'm new to this API stuff so I aplolgize for my little knowledge.  I've downloaded the "cc_class.php" script and made the changes to reflect the lists I want users to see.  I also added my sign in, password and key code as well.   What I don't know is what is the next step?  Where do I put this script - in my web page, or do I upload it and link to it, or what?  And how does it link to the subscribe here button on my site.


Thanks for the help.


Pamela

Pamela

Employee

Pamela,


 


Now that you have modified the cc_class.php file you will need to upload that, along with the following files, into a single directory:


1: A form to collect the data such as the included add_contact.php, simple_form.php, or your own custom form.

2: contries.txt

3: states.txt

4: styles.css


 


Once you have uploaded those files into a single directory on your webserver you should be able to access the form and submit the information.


 


Please try those steps and feel free to ask any additional questions.


 

Dan H

Support Engineer, Constant Contact

Regular Participant

Hi,


I'm trying to use the sample code to create a single list subscription form but it isn't working. I've pared the form down to just the subscribers email address and mailing preference.  I included a hidden field for the list I want to use (#32).  When I submit the form, all I get back is a generic "An Error Occurred".  How can I find what the error is?


If it helps, here's my form:


<form action="" method="post">

<div style="float: right; text-align: left; overflow: auto; height: 640px; width:250px;">

<input type="hidden" name="lists[]" value="32" />  <?php // List# for Yellow Pages ?>

</div>  



<div>

<h3>Contact information</h3>  



<table width="580" border="0" cellpadding="2" cellspacing="0">

 <tr>

  <td align="left">Email Address:</td>

  <td align="left"><input type="text" name="email_address" value="<?php echo $postFields?>" maxLength="100" /></td>

  <td align="left">&nbsp;</td>

  <td align="left">&nbsp;</td>

 </tr>

 <tr>

  <td align="left">E-Mail Type:</td>

  <td align="left" colspan="3">

   <input type="radio" class="checkbox" name="mail_type" id="mt1" value="HTML" <?php echo ($postFields == 'HTML' || $postFields == '') ? ' checked ' : '';?> />

   <label for="mt1">HTML</label>

   &nbsp;or&nbsp;

   <input type="radio" class="checkbox" name="mail_type" id="mt2" value="Text" <?php echo ($postFields == 'Text') ? ' checked ' : '';?> />

   <label for="mt2">Text</label>

  </td>

 </tr>

 <tr>

  <td align="center" colspan="4">

   <input type="submit" name="submit" value="Add Contact" />

  </td>

 </tr>

</table>



</div>

</form>

 


Thanks,


Gary


 

Employee

Hey Gary,


 


There may be more than one reason that your script is not functioning but it will be hard to tell without seeing the other parts of your code specifically the submission portion.


 


I can say that I have noticed one mistake in your form. In the input field named "lists[]" you are specifying the value as a number: value="32" The lists fields must contain the full URI of the list like so: value="http://api.constantcontact.com/ws/customers/{username}/lists/32"


 


Please try that modification and if you are still unsuccessful I would recommend attaching the rest of your source code. Do remember to obfuscate any account details.


 


I would also recommend turning on the debug option in the cc_class.php file by setting var $curl_debug = true; so that you see what the actual errors may be as opposed to the less-than-helpful 'An Error Occurred' message.


 


Let us know if you need any other help.

Dan H

Support Engineer, Constant Contact

Developer Portal

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

Visit Page