Forums

Making Constant Contact work with Chronoform 3

primalduty 14 Nov, 2014
Has anyone successfully integrated constant contact (Ctct) into a chronoform?

It seems pretty straight forward according to this post, but this post may not work with current code as there is not a date (year) on it. http://www.chronoengine.com/faqs/61-cfv4/cfv4-tutorials/3452-how-can-i-build-a-constant-contact-sign-up-form-.html

1. Upload the Ctct API code
2. Then use a custom code action OnSubmit to execute the Ctct php to process the request.(I'm using the "View" mode on the custom code event)

I have implemented Ctct on many basic html forms but currently receiving an error.

Here is the current error I receive:

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/bodylift/public_html/administrator/components/com_chronoforms/form_actions/custom_code/cfaction_custom_code.php(15) : eval()'d code on line 4

I attached the php code I'm using in the custom code action.

Any help would be appreciated,
Mike
primalduty 15 Nov, 2014
UPDATE: I found the error was not caused by the constant contact code. The "Redirect URL" was causing it. When I changed the action to "Redirect User" the application did not throw any errors. But I'm still not getting inserting any visitor info into the Constant Contact list. Has anyone had success using Constant Contact with ChronoForms?
GreyHead 15 Nov, 2014
Hi Mike,

The ReDirect User action will work if you add a URL; or if you have previously set a URL in the ReDirect URL action and leave the URL in the ReDirect User action empty.

The code attachment isn't here - there is/was an error on or before line 4 of the code. That's a comment in the FAQ so looks a bit odd

The FAQ was written for ChronoForms v3 - as you are using Joomla! 2.5 I think you must be using ChonoForms v4?

As some point between Joomla! 1.5 and 3 they stopped defining DS - it may be that was causing an error?

Bob
primalduty 17 Nov, 2014
Thank for your reply GreyHead.

Am I correct in assuming if I have the constant contact code in the correct directory and call it correctly, then use a custom code action OnSubmit to execute the Ctct php to process the request?

Below is the code I'm using in the custom code action. I have tried both Modes (controller and view).

OUTCOME: Form is submitted properly, email is sent indicating the onSubmit action is working but no error is thrown and no email is added to the Constant Contact list. I will set up a non-Chronoform form to validate that I can hit the constant contact list wile waiting for a response. Our form consist of the same form values CC is requesting i.e., email, list, first_name, last_name

Mike

<?php
require_once 'http://bodyliftsurgerycenter.com/components/com_chronoforms/extras/constant_contact/Ctct/autoload.php';

use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;

define("APIKEY", "OUR API KEY");
define("ACCESS_TOKEN", "OUR ACCESS TOKEN");

$cc = new ConstantContact(APIKEY);

// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try{
    $lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
    foreach ($ex->getErrors() as $error) {
        print_r($error);
    }     
}

// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
    $action = "Getting Contact By Email Address";
    try {
        // check to see if a contact with the email addess already exists in the account
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);

        // create a new contact if one does not exist
        if (empty($response->results)) {
            $action = "Creating Contact";

            $contact = new Contact();
            $contact->addEmail($_POST['email']);
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];
            $returnContact = $cc->addContact(ACCESS_TOKEN, $contact); 

        // update the existing contact if address already existed
        } else {            
            $action = "Updating Contact";

            $contact = $response->results[0];
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];
            $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);  
        }
        
    // catch any exceptions thrown during the process and print the errors to screen
    } catch (CtctException $ex) {
        echo '<span class="label label-important">Error '.$action.'</span>';
        echo '<div class="container alert-error"><pre class="failure-pre">';
        print_r($ex->getErrors()); 
        echo '</pre></div>';
        die();
    }
} 
?>
primalduty 17 Nov, 2014
I changed the require_once to an absolute path... require_once '/home/bodylift/public_html/components/com_chronoforms/extras/constant_contact/Ctct/autoload.php';

but I still receive this error from the error log:

[17-Nov-2014 16:38:16] PHP Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/bodylift/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 4

Here is the block of code that is failing:

13 function run($form, $actiondata){
14 $mainframe =& JFactory::getApplication();
15 $params = new JParameter($actiondata->params);
16 if($params->get('mode', 'controller') == 'controller'){
17 $message = $actiondata->content1;
18 eval('?>'.$message);
19 }
20 }

Question #1 - Can someone tell me if the var $message is the Code within the custom code action?

Outcome: When I change the mode to "View" the application does not throw an error but it still does not insert conact into the list.

Question #2 - Has anyone successfully integrated constant contact into a chronoform?

Mike
primalduty 17 Nov, 2014
So I just read up on mode and it tells me I should be using controller mode to process the constant contact code. This is from the help section on the Chronoforms Custom Code page. Running this as Controller is required if you want to do some data processing for some serverside stuff like sending emails, uploading files, saving data or even processing some payment gateway response.

That answers why when I switched to view mode there were not any errors and not any new contacts in the Constant Contact list.

So, I'm back at square one. Chronoforms is still throwing an exception with using the constant contact code.

[17-Nov-2014 17:52:52] PHP Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/bodylift/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 4

Using Version: 4.0 RC3.4.1
GreyHead 18 Nov, 2014
Hi Mike,

This PHP error message "PHP Parse error: syntax error, unexpected T_STRING, . . . /custom_code.php(18) : eval()'d code on line 4" says that there is an error in Line 4 of the code that is being evaluated. Your Custom Code in this case, not the ChronoForms code where the eval('?>'.$message); code is.

I think that the problem is that you have used a URL in the require_once line and a folder path is expected. Please try:
<?php
require_once JPATH_SITE.'/components/com_chronoforms/extras/constant_contact/Ctct/autoload.php';

use Ctct\ConstantContact;

Bob
primalduty 18 Nov, 2014
Not working 😟 I have to find another solution. Chronforms is not playing nice with constant contact.

Thanks,
Mike
primalduty 18 Nov, 2014
Like you said GreyHead, it's probably not be Chronoforms throwing the error. I found that the the program was crashing at the php "use" command. Seems php 5.2 does not support namespaces and Constant Contacts code uses them. When I updated the PHP to 5.4 it crashed my site.

No fun working with old websites. I'll test the CC integration with Chronoforms on one of my newer sandbox site and update this post with my findings. Just wanted to update you.
primalduty 18 Nov, 2014
The issue was in fact like I mentioned above, "I found that the the program was crashing at the php "use" command. Seems php 5.2 does not support namespaces and Constant Contacts code uses them. When I updated the PHP to 5.4 it crashed my site."

So, I successfully integrated the Constant Contact API on a simple HTML website and a Joomla 3+ website using Chronoforms5. I will now go back to the original website, update the PHP engine to 5.4 and retry the Chronoforms V4 custom code action I have and let you know how it worked.
primalduty 18 Nov, 2014
It worked, the problem was the fact that the server was using an old version of PHP. As soon as I updated the server to run 5.4 the code worked like a charm.

Oh and your suggestion to use JPATH_SITE. was a life saver
GreyHead 19 Nov, 2014
Hi Mike,

Thanks for letting up know. I hadn't spotted the potential problem with Namespaces and PHP versions.

Bob
This topic is locked and no more replies can be posted.