cancel
Showing results for 
Search instead for 
Did you mean: 
Due to an issue with YouTube, inserting videos in your emails is showing an error. Until they are able to resolve this issue, we recommend using a different video hosting service. We will continue to monitor this outage and update you as we have more information.

Create a signup form that limits user to one list

CTCT Employee

Hey Gary,   There may be more

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

Occasional Participant

Thanks for the help, Dan - I

Thanks for the help, Dan - I think I'm getting closer.  With debug turned on, I'm getting a 403 error message.  The account username contains a space - could that be the problem?  I tried using %20 in place of the space but then I get a 401 error message.  I tried replaceing the space in both the URI that you sent and $login in cc_class.php.


Gary


Here's the entire submit form code.  Other than the login credentials, cc_class.php is unchanged.


<?php

include_once('inc/cc_class.php');

$ccOBJ = new ConstantContact();



$postFields = array();

$postFields = (isset($_POST) ? $_POST : '');

$postFields     = (isset($_POST)     ? $_POST     : '');

$postFields         = (isset($_POST)         ? $_POST         : '');



if (!empty($_POST)) {



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



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

  $error = true;

 } else {

  $error = false;

  $_POST = array();      

 }

}



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



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



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



<?php

if (isset($error)) {

 if ($error === true) {

  $class = "error";

  $message = $ccOBJ->lastError;

 } else {

  $class = "success";

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

 }



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

}

?>



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

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

<input type="hidden" name="lists[]" value="http://api.constantcontact.com/ws/customers/xxx xxxxxxxx/lists/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>

</div>

 

CTCT Employee

Thank you for the additional

Thank you for the additional information. I was able to test your script alongside the default cc_class file and my account credentials and it worked perfectly. I then changed my account name to contain a space and replicated the 403 error that you were getting.


 


By modifying one line in the cc_class file I was able to get the form to process with the space in the username. Around line 31, there should be a public function called __construct(). If you modify the line that reads:


$this->apiPath = $this->apiPath.$this->login;


to read


$this->apiPath = $this->apiPath.rawurlencode($this->login);


it should resolve your issue. This modification encodes the request URI to have a %20 instead of the space. This encoding is not necessary for the credentials and infact, cannot be done for the credentials.


 


Please let me know if you require any clarification.

Dan H

Support Engineer, Constant Contact

Occasional Participant

Thanks, Dan.  That did

Thanks, Dan.  That did it!


Gary

Occasional Participant

Remove from Single List

While the add function now works, I noticed that the delete function requires only an email address.  Does this mean that if a person unsubscribes using deleteSubscriber() in cc_class.php, that the email address is removed from ALL lists?  How would I control it to delete the address from a specific list?  Passing "$contactXML" as for addSubscriber() doesn't work.  In my client's case, it definately will be the case that an email address will be in multiple lists but the owner may want to unsubscribe only from the list I'm putting together.


Gary


 

CTCT Employee

The term 'Unsubscribe'

The term 'Unsubscribe' implies that the contact is looking to remove them-self from all lists. If you would like to give the ability to have a contact remove them-self from one list, you would need to update the contact details and choose to omit that list from their collection of lists that they are subscribing to.


 


The editSubscriber() function is used for updating the contact information. Please note that you will need to re-specify all of the lists that they would like to remain subscribed to.

Dan H

Support Engineer, Constant Contact

Occasional Participant

I was hoping to just provide

I was hoping to just provide a way for subscribers to remove themselves from the new list without any extra effort on their  part to indicate on which lists they want to remain.  Any chance of creating such a function?  Simply the reverse of adding to a specific list?  Or, is there a way for me to know programmatically which other lists they are on and keep them there?


Gary


 

CTCT Employee

That is definitely possible

That is definitely possible and fairly easy to implement.


 


Prior to updating the contact, you would need to perform a GET to the contact id to find out what lists they are currently on. Once you have that information you can populate a series of hidden input fields, each with the name 'lists[]' and a value of the list URI such as: value="https://api.constantcontact.com/ws/customers/{username}/lists/1". In the PHP sample there should be an edit_contact.php file that contains most of the logic to do what you are looking to do.


 


Now, when you submit the update, you will be 'resubscribing' them to the appropriate lists.


 


Your logic may vary depending on how you want to remove them from certain lists however knowing how to retrieve and resubmit the lists should be a large part of this solution.


 


Please let me know if you need any clarification.

Dan H

Support Engineer, Constant Contact

Occasional Participant

I tried running

I tried running edit_contact.php with no changes and called up several email addresses.  In all cases, the "Interest lists" box remained empty.  Shouldn't I have seen at least one entry there?


Gary


 

New Member

PHP example??? Where is it?

I clicked to see the example and nothing came up. Any Advice?


Thanks, Steve