Hi all,

Can anyone comment on CRM integration module development? I see there is an existing CRM API module as well as one which integrates with the Loopfuse CRM. We are using Eloqua, which is similar.

I need a group of contact/registration forms to re-post their contents to Eloqua, so folks who enter their information get placed into the CRM for reference. If the forms were straight HTML this would be trivial but I'm not sure how to go about writing a module which would do the form alter hook properly for this purpose. As far as I know all we need to do is add some hidden fields and integrate the re-posting to the Eloqua URL.

Any help would be much appreciated, I'm looking forward to contribute to the Drupal community which has given me so much.

Regards,
-Patrick

Comments

AaronBauman’s picture

you can use the #action attribute to post to any url.
check out the forms quickstart guide and the forms api reference.

pkrekelb’s picture

Thank you for your comment. Can you give me an example of how this might be used in a module to alter the contact form, for instance, to add some hidden fields and change the action?

pkrekelb’s picture

any more thoughts on how to make "re-posting" form submissions happen, fellas?

mohirt’s picture

I am also in need of passing information submitted through a Drupal form to Eloqua.. I know it can be done!

Kevin P Davison’s picture

Please let me know what you find, as I have a need for this too...

@Quevin — Sr. Technical PM

Dijup Tuladhar’s picture

I found the solution for the contact us page as my task was just to send the info to other site

/**/
//new dBug($form_state);
// remote URL we want to post to
$url = '***site url***';
// set our headers
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded',
);
// the actual sending of the data
$response = drupal_http_request($url, $headers, 'POST', http_build_query($form_state['values'], '', '&'));

// if we get a good response, thank user for submission
if ($response->code == 200) {
drupal_set_message(t('Message'));
// otherwise let them know something went wrong
} else {
drupal_set_message(t('Message'), 'error');
}
/**/

but still no solution for the registration form.

bishwadeep’s picture

Hi all I have a similar problem. I want to implement Eloqua in my drupal registration form. Can anybody help me on this or tell me if there is any modules for this.

doublejosh’s picture

I'm also doing this in the next month or so for work. Hoping a module is forthcoming. Anyone wanna team up?

ndwilliams3’s picture

Also looking at doing this. Eloqua makes this process more difficult with having multiple forms and custom form fields. you can't use standard field definitions in the module. I have been looking around to see how this would be possible.

I am looking at using Webform 3.x with the new hooks API.

Also looking at the following to tie in the registration.

http://drupal.org/project/webform_register
http://drupal.org/project/webform_registration

FYI, The author of webform_registration has built a private module that ties in with Eloqua for one of his clients.

Here is a php class to perform Data lookups in Eloqua if you are interested!
http://github.com/j-lee/Eloqua-Lookup

My PHP skills are basic, so who knows if if I can even get something working.

@doublejosh, while I may not be able to offer anything on the programming side, I use Eloqua on a daily basis and would be willing to collaborate with you on UI and integration methods.

ndwilliams3’s picture

below is the code to provide a custom action module to post data to Eloqua. Sorry, no upload on Forum! Create a folder called "eloqua_integration" in your sites/all/modules folder and save both the files to it. Enable profile.module, token.module, token_profile.module, trigger.module and this module. Add profile fields to registration form for the data you would like to collect in Eloqua. Go to admin/actions/manage and add new "Post to Eloqua" action and input URL and set fields using profile tokens. Go to /admin/build/trigger/user and assign action to "Trigger: After a user account has been created". Data will post to Eloqua when a user registers. Still working on webform integration, but this solves part of my problem.

Based on http_action module

eloqua_integration.info

; $Id:$
name = Eloqua Integration
description = Exposes Drupal actions to send User and Profile Data to Eloqua.
php = 5.1
core = 6.x
dependencies[] = 'profile'
dependencies[] = 'token'
dependencies[] = 'token_profile'
dependencies[] = 'trigger'

eloqua_integration.module

<?php
// $Id:$

/**
 * @file
 * Exposes Drupal actions for sending data to Eloqua.
 */

/**
 * Implementation of hook_action_info().
 */
function eloqua_integration_action_info() {
  return array(
    'eloqua_integration_data_post_action' => array(
      'type' => 'system',
      'description' => t('Post Data to Eloqua'),
      'configurable' => TRUE,
      'hooks' => array(
        'nodeapi' => array('view', 'insert', 'update', 'delete'),
        'comment' => array('view', 'insert', 'update', 'delete'),
        'user' => array('view', 'insert', 'update', 'delete', 'login'),
        'taxonomy' => array('insert', 'update', 'delete'),
      ),
    ),
  );
}

/**
 * Return a form definition so the Send Post action can be configured.
 *
 * @param $context
 *   Default values (if we are editing an existing action instance).
 * @return
 *   Form definition.
 */
function eloqua_integration_data_post_action_form($context) {
  // Set default values for form.
  
  $form['uri'] = array(
    '#type'          => 'textfield',
    '#title'         => t('Eloqua Post URI'),
    '#default_value' => isset($context['uri']) ? $context['uri'] : '',
    '#size'          => 80,
    '#required'      => TRUE,
  );

  $form['data'] = array(
    '#title'         => t('Form Data'),
    '#type'          => 'textarea',
    '#default_value' => isset($context['data']) ? $context['data'] : '',
    '#columns'       => 80,
    '#rows'          => 3,
    '#description'   => t('Form Data to be sent to Eloqua. One line per form value in the format name:value. form names must match exactly with Eloqua.'),
    '#required'      => TRUE,
  );

  $form['help'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Placeholder tokens'),
      '#description' => t("The following placeholder tokens can be used in any of the above fields. Some tokens may not be available, depending on the context in which the action is triggered."),
    );

    $form['help']['tokens'] = array(
      '#value' => theme('token_help', 'all'),
    );
  
  return $form;
}

function eloqua_integration_data_post_action_submit($form, &$form_state) {
   // Process the HTML form to store configuration. The keyed array that
  // we return will be serialized to the database.
  return array(
    'uri'			 => $form_state['values']['uri'],
    'data'           => $form_state['values']['data'],
  );
}

/**
 * Implementation of a configurable Drupal action.
 * Sends an email.
 */
function eloqua_integration_data_post_action($object, $context) {
  eloqua_integration_normalize_context($context);

  $uri      = token_replace_multiple($context['uri'], $context);
  $data_tmp = token_replace_multiple($context['data'], $context);
  $method   = 'POST';
  $headers  = array(
      'Content-Type' => 'application/x-www-form-urlencoded'
  );
  
  $fields = explode("\n", $data_tmp);
  $fields_array = array();
  foreach ($fields as $field) {
    $bar = explode(':', $field, 2);
    $fields_array[$bar[0]] = urlencode(trim($bar[1]));
  }

  // stringify the data for the POST
  $data = '';
  foreach ($fields_array as $key=>$value){
    $data .= $key.'='.$value.'&';
  }
  rtrim($data, '&');
  
    
  drupal_http_request($uri, $headers, $method, empty($data) ? NULL : $data);
  
  if (drupal_http_request($uri, $headers, $context['method'], $data)) {
    watchdog('action', 'http request to %uri', array('%uri' => $uri));
  }
  else {
    watchdog('error', 'Unable to send http request');
  }
}

/**
 * Load, into the context, the common objects user and node so we can use their
 * tokens. Sometimes Trigger, or Actions, load them for us, but sometimes not.
 */
function eloqua_integration_normalize_context(&$context) {
  $context['global'] = NULL;
  if (empty($context['user']) && !empty($context['node'])) {
    $context['user'] = user_load(array('uid' => $context['node']->uid));
  }
  if (empty($context['node']) && !empty($context['comment']) && !empty($context['comment']->nid)) {
    $context['node'] = node_load($context['comment']->nid);
  }
  if($context['hook'] == 'user' && !empty($context['account'])) {
      $context['user'] = $context['account'];
  }
}
doublejosh’s picture

We have a custom Eloqua module that pushes an async post when the registration form is filled out as well as a few other purely submit button hidden item forms.

Potentially willing to do some work to pull this out into a real module, but I feel like the Eloqua people should probably provide some kind of resources since it enables Drupal sites to use their paid service.