Forums

Chronoforms and GetResponse

awilkin 24 Aug, 2010
Hi Forum,

This is me giving back after everyone has been so helpful to me🙂

I integrated my form with GetResponse, I chose this service because they allow a number of features including an API and split testing. Please note I am not endorsing one service versus another.

Once you have registered for the paid service you can get an API key - this is essential for what I do here. I have not used the CURL interface, but please do not rule this option out because of my approach.

Having got your API key, you will need to download the JSON php wrapper: http://jsonrpcphp.org/?page=download&lang=en

Place it somewhere accessible by your webserver (you will specify this path later in the script).

In the On Submit Code (your choice if before or after email but note caveats about enabling email if placing in the before), put:

<?php
# JSON-RPC module is required
# check 'Getting started with PHP' page in API documentation
require_once 'PATH_TO_FILE_DOWNLOADED/jsonRPCClient.php';

# your API key
# check 'How to get API key' page in API documentation
$api_key = 'YOUR_KEY';

# API 2.x URL
$api_url = 'http://api2.getresponse.com';

# initialize JSON-RPC client
$client = new jsonRPCClient($api_url);

$result = NULL;

# You need to supply Name (my form included First and Last Name - Get Response requires a name)
$name = JRequest::getVar('First_Name', 'Sir/Madam', 'Post') . ' ' .
        JRequest::getVar('Last_Name', '', 'Post') ;

$email = JRequest::getVar('Email', '', 'Post') ;

$ip_addr = $_SERVER["REMOTE_ADDR"];

# get CAMPAIGN_ID of 'sample_marketing' campaign
try {
    $result = $client->get_campaigns(
        $api_key,
        array (
            # find by name literally
            'name' => array ( 'EQUALS' => 'YOUR_CAMPAIGN_NAME' )
        )
    );
}
catch (Exception $e) {
    # check for communication and response errors
    # implement handling if needed
}

# uncomment this line to preview data structure
# print_r($result);

# since there can be only one campaign of this name
# first key is the CAMPAIGN_ID you need
$CAMPAIGN_ID = array_pop(array_keys($result));

try {
    # call method 'add_contact' and get result
    $conditions = Array(
        'campaign' => $CAMPAIGN_ID,
        'action' => 'standard',
        'name' => $name,
        'email' => $email,
        'cycle_day' => '0',
        'ip' => $ip_addr
    );
    $result = $client->add_contact($api_key, $conditions);
}

catch (Exception $e) {
    # check for communication and response errors
    # implement handling if needed
}
?>

Hope this helps my fellow borders...

Andy
http://www.star-builder.co.uk
This topic is locked and no more replies can be posted.