cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Started with the Sample Upload Forms in PHP

Administrator

This page is intended to help users use the PHP Upload Form sample application.

 

1. Authentication data

 

First, you must set up the API Key, account Username and Password in order to use these sample forms to access the Constant Contact resources. The following features are available: add a new Contact (using the full or simplified from), search for a Contact and then add it or update it (both Contact adding or updating is performed using the simplified from), remove a Contact from all lists and unsubscribing a Contact (opted-out Contacts become members of the "Do-Not-Mail" special list).

 

To set up the authentication data, you need to change the following variables in class file (cc_class.php) that can be found in the project, as shown in lines 11-13:

  • $apikey: API Application Key and is used to identify the application making an API request
  • $login: Constant Contact Customer's user name
  • $password: Constant Contact Customer's password.

Example of code:

 

 

2. Customizing contact lists

 

There are several different ways for you to customize the contact lists that are used in the sign up form.  First, you can use all lists, which is the default behavior, or you can select which lists you want to work with in the sign up form.  Then, you can decide whether you want to give your contacts a choice of selecting contact lists.  You can either automatically sign them up to one or more lists of your choosing, or give them a chance to select lists.  Finally, if you decide to sign them up to one or more default lists automatically, then you can decide whether to display these contact lists or not.

In order to customize the displayed lists you will need to make some changes in the ConstantContact class from the cc_class.php file, found in PHP sample application.

$contact_lists array is used to specify contact lists you would like to either display for the users to select or sign them up by default.  If you do not specify anything, then all contact lists will be used by default.  For example, if you want to display or force users to only "Baseball List" and "Football List", you would modify the line to:

var $contact_lists = array('Baseball List', 'Football List');

$force_lists determines whether users are given a choice to choose which lists they sign up for or the form automatically signs them up.    For example, if you set this flag to true, then users will be automatically signed up for "Baseball List" and "Football List".  Of course, if you have not specified $contact_lists, then the users will be signed up for all contact lists by default.  If you leave $show_contact_lists to be true while $force_lists is false, then users will be told which lists they are signing up for, but will not get a chance to make any selection.

$show_contact_lists determines whether contact lists are displayed to the user or not.  This flag is useful only if $force_lists is set to true.  If $force_lists is set to false, i.e. the contacts can choose which lists they can sign up for, the contact lists will not be hidden.  For example, if you leave $show_contact_lists to be true, then the sign up forms will only display "Baseball List" and "Football List".  If you set this to false and set $force_lists to be true, then the users will not be shown "Baseball List" and "Football List" and they will be signed up to those two lists automatically.

 

3. Create a New Contact

 

Users can create a new Contact by filling out the full or the simplified form . For the full form they can provide the following informations for the new Contact: Email Address, First Name, Last Name, Middle Name, Home Phone, Address, City, State/Province, Zip/Postal Code, Sub Zip/Postal Code, Country, Company Name, Job Title, Work Phone, Email Format, Notes, Custom field 1 - 15 and Contact Lists on which the newly Contact would receive occasional email.

Required fields are: Email Address and at least one Contact List should be checked.

 

For the simplified form they can provide the following informations for the new Contact: Email Address, First Name, Last Name, Middle Name, Home Phone, Address, City, State/Province, Zip/Postal Code, Sub Zip/Postal Code, Country and Contact Lists on which the newly Contact would receive occasional email.

Required fields are: Email Address and at least one Contact List should be checked.

 

If the contact does not exist or does not belong to “Do-Not-Mail” list, the contact will be added to the chosen lists and you are given the message below.

 

 

Note that this only works for a brand new contact that does not belong to any list. If a contact already exists, in any contact list, then you are notified that the contact already exists. To update an existing contact to another list, then you have to go into “Update” mode as described below.

 

4. Add or Edit a Contact

 

The Add or Edit a Contact section allows users to write an e-mail address and sign it up into their constant account. After clicking the Sign Up button the written e-mail address is searched in the user Constant Contact account.

If the e-mail address does not exist, then users are automatically redirected to the page that allows them to create a new Contact using the simplified form. On the create new Contact form, the E-mail Address field is automaticaly filled with the e-mail address provided on the Add or Edit a Contact page. You can enter Contact informations in this form and after that, pressing the Add Contact button will create the desidered Contact in your Constant Contact account.

If the e-mail address exists, then users are automatically redirected to the page that allows them to update that Contact using the simplified form. Using this screen, you can now edit each field as well as unsubscribe the Contact from a list by un-checking a list and subscribe to a list by checking it.

The Add or Edit a Contact form consists of the following web page sources: edit_contact_step1.php, edit_contact.php, simple_form.php.

5. List all Contacts

 

The List all Contacts option will display all contacts that the acount owner have. Edition of a contact can be performed by clicking on the Edit link. The Remove link will remove the contact from all lists. Since the Constant Contact REST API uses chunk data, this page also displayes information using chunks (50 contacts on page). The Next link, below the table, will perform another query that will retrieve from the Constant Contact server next 50 contacts and if you press it again it will display the next 50 contacts. When there are no next contacts, then the link it will be automaticaly disabled. The First Page link will get the first 50 contacts from the server and you will be able after that to get the next available contacts from the server (if there is the case).

 

 

6. Unsubscribe a Contact

 

Using the update form (simplified form - from the Add or Edit Contact menu item or full form - from the List all Contacts menu item) users have an option to unsubscribe it all lists using the "Unsubscribe me from all lists" check box marked in the image below. Checking this will remove the contact from all lists and add the user to the "Do-Not-Mail" list.

 

7. Remove a Contact

 

Using the List all Contacts, users can remove a Contact (removing it from all lists) by clicking the Remove link. The Contact Status will be changed from Active to Removed. Only contacts that are Active can be unsubscribed from all lists. To change the status of a removed contact, click the Edit link, subscribe it to any list(s) and update it's profile. The status of the contact will be changed from Removed to Active.

 

8. How-To use it

 

This PHP SAMPLE APPLICATION consists of the following files:

  • index.php - this class contains API Key, Username and Password used to acces Constant resources. Also, it contains definition for State/Province and Country
  • [BaseFolder]\images - [DIR] - this directory contains all relevant images included in this sample
  • [BaseFolder]\countries.txt - [FILE] - this text file contains the list with all countries available in ConstantContact. Each country is on a separate line, together with its country code.
  • [BaseFolder]\states.txt - [FILE] - this text file contains the list with all states available in ConstantContact. With this lines are populated comboboxes in our sample application.
  • [BaseFolder]\style.css - [FILE] - StyleSheet used to beautify our Sample Application.
  • [BaseFolder]\cc_class.php - ConstantContact API class. This file contains the Class developed to communicate with ConstantContact API
  • [BaseFolder]\header.php - File with a basic design for header. It contains the image and menu navigation which is included in all forms within the sample application.
  • [BaseFolder]\index.php - default file for this sample application
  • [BaseFolder]\list_contacts.php - php file which is displaying all the contacts for current account.
  • [BaseFolder]\add_account.php - php file which is desinged to display the full `add contact` form. It contains all available fields in ConstantContact.
  • [BaseFolder]\simple_form.php - same `add contact` form, just that this is the shorten form. It displays only few PERSONAL INFORMATION fields.
  • [BaseFolder]\delete_contact.php - file that is executed when user click on REMOVE link from `LIST ALL CONTACTS` form. Normally by executing this script, it changes the STATE for selected contact to REMOVED.
  • [BaseFolder]\edit_contact_step1.php - displays a simple search form for a contact. If specified contact exists, then user is redirected to Edit Contact form. Otherwise user is redirected to Add Contact form.
  • [BaseFolder]\edit_contact.php - php file that is designed to edit a contact profile. Here User can modify ALL the fields available in ConstantContact.

webservices