Basics for a major noob.


Basics for a major noob.

 Hello all, I've been working with PHP for a while but I will admit that I haven't done a lot with Classes and the like.  I've got my API key, got the wrapper file, included it successfully and I've looked at the example files...but they tend to throw everything in there and its hard to sort out where to start.

What I'd like is very simple, stripped down PHP example of how to use a simple contact form (email field, button) to add a new person to a list using the wrapper class.




Our published sample forms are using an older class file to handle all the contact submission and other processing. However, I believe I can whip up a quick sample of how this would work with the wrapper library for you. I will post here when I've got that completed.

David J


I think this is going to get you where you need to be. We're going to make some slight modifications to the way the library adds contact lists, but we will post when that happens as well as some new examples for adding contacts. I hope this helps. Please let me know if you have any questions.



// If the form is submitted add the Contact



    //Instantiate the Lists and Contacts Collection

    $ContactsCollection = new ContactsCollection();

    $ListsCollection = new ListsCollection();

    //Get a list of Constact lists for your account

    $listsArray = $ListsCollection->getLists();

    $generalInterest = $listsArray;

    // Set properties for the contact from the form that was submitted

    $Contact = new Contact();





    $httpResponse = $ContactsCollection->createContact($Contact);


    // Display success or failure code

    if($httpResponse == 201){

        echo "Contact Added";


        echo "There was an issue adding this Contact";






    <title>Join our Mailing List</title>



<h1>Join our Mailing List</h1>

<form name="myForm" action="">

Email Address: <input type="text" name="emailAddress"><br />

First Name: <input type="text" name="firstName"><br />

Last Name: <input type="text" name="lastName"><br />

<input type="submit" name="submit" value="Join Now!">





David J

I am wondering why I have to use php at all. Is there an example where I am just using html with no wrapper?

Unfortunately a language capable of sending http requests such as PHP, C#, ColdFusion, Python, Java, Groovy, Ruby, VB..etc. An HTML form would have no mechanism to send that request to Constant Contact. With that being said you may have some use for the Constant Contact Signup Form Generator, which does not require any programming knowledge to implement.

David J

Developer Portal

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

Visit Page