Using php to insert new contact

Highlighted
New Member

Using php to insert new contact

 Ok, I've been trying to sort this our for a long time.  I know the question has been asked, but I just can't seem to find the right information.


All I want to do is submit new contact info from a simple html form (on my website) and insert that data into my contact list.  I have looked at the sample code for this but there are over 1000 lines of code in there and I jsut don't know what is neccesarry or not.  So can someone please tell me what the essential bits of PHP are in order to submit data to my contact list?


all I want to do is add name, email, city.  I have the html form, I just need the PHP.   

 David Breion


www.NiftyBalloons.com

1 REPLY 1
Highlighted
Employee

Re: Using php to insert new contact

The Constant Contact Signup Form Generator might be a good option for you. This allows you to generate custom HTML forms for your website without having to know any PHP.


If you have an existing form and want to make that deposit a contact in your account, the PHP Sample Contact/Upload form on our Code Samples would likely be the best place to start. Your would want to begin by looking at the add_contact.php page, which contains an HTML form that will add contacts to your account. This form requires that cc_class.php is included and contains your Constant Contact username, password, and api key. The part you would need to submit a contact is below.


// Instantiate CC_Contact class

include_once('cc_class.php');

$ccContactOBJ = new CC_Contact();



// If $_POST is not empty, we assume the form has been submitted

if (!empty($_POST)) {

// At this point we would want to set all of the postField variables to be whatever information was submitted through your form. The required fields would be $postFields and $postFields

        $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;

        $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;

            }

        }

        // Create XML from the data stored in the postFields array

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

         

        // Make http request submitting the data for this new contact

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

            $error = true;

        } else {

            $error = false;

            $_POST = array();

        }



    }

I hope this helps. If you have any questions regarding this please let us know. Thanks.

David J

Developer Portal

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

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Aug 13 retail why ctct banner.png

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

 

Online marketing presents opportunities for retail stores to get found, get more sales, and ultimately grow the business.

 

If you’re just getting started with online marketing or not seeing the results you’ve hoped for then this session is for you. With our guest expert, Bryan Caplan, you’ll learn a smarter, more practical approach to getting the word out about your retail store. From making sure your business is found to keeping it top of mind, find out how to get the word out to the people who matter most online.

 

Read More
Featured