Basics for a major noob.

Highlighted
New Member

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.


Thanks!

Chris

4 REPLIES 4
Highlighted
CTCT Employee

Re: Basics for a major noob.

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

Highlighted
CTCT Employee

Re: Basics for a major noob.

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.


<?php

include_once('ctctWrapper.php');



// If the form is submitted add the Contact

if(isset($_REQUEST))

{

    //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();

    $Contact->setEmailAddress($_REQUEST);

    $Contact->setFirstName($_REQUEST);

    $Contact->setLastName($_REQUEST);

    $Contact->setLists($generalInterest->getId());



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



   

    // Display success or failure code

    if($httpResponse == 201){

        echo "Contact Added";

    }else{

        echo "There was an issue adding this Contact";

    }

}

?>



<html>

<head>

    <title>Join our Mailing List</title>

</head>



<body>

<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!">

</form>



</body>

</html>

 

David J

Highlighted
Member

Re: Basics for a major noob.

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

Highlighted
CTCT Employee

Re: Basics for a major noob.

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

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured