You are here

function eloqua_form_alter in Eloqua 6

Implementation of hook_form_alter().

File

./eloqua.module, line 264

Code

function eloqua_form_alter(&$form, $form_state, $form_id) {

  // We only want to edit client versions of the webform. If it's anything else
  // simply return.
  if (strpos($form_id, 'webform_client_form') !== 0) {
    return;
  }
  if (!isset($form['details']['nid']['#value']) || empty($form['details']['nid']['#value'])) {
    return;
  }
  $nid = $form['details']['nid']['#value'];
  $form_settings = (array) eloqua_webform_load($nid);

  // Check to see if the form exists
  if (empty($form_settings) || !$form_settings[ELOQUA_WEBFORM_FIELD_ACTIVE]) {
    return;
  }

  // Check for QUERY parameter mappings to assign default values
  _eloqua_form_url_map($form, $form['#parameters'][2]->webform['components']);

  // Just shove everything into a container
  $form['#submit'][] = 'eloqua_webform_submit';
  $form['eloqua'] = array();
  $process_every_page = is_object($form_settings[ELOQUA_SETTINGS_FIELD_DATA]) && isset($form_settings[ELOQUA_SETTINGS_FIELD_DATA]->process_every_page) ? $form_settings[ELOQUA_SETTINGS_FIELD_DATA]->process_every_page : FALSE;
  $form['eloqua']['process_every_page'] = array(
    '#type' => 'value',
    '#value' => $process_every_page,
  );
  $form['eloqua']['elqFormName'] = _eloqua_form_hidden($form_settings[ELOQUA_WEBFORM_FIELD_FORM_NAME]);
  $form['eloqua']['elqSiteId'] = _eloqua_form_hidden(eloqua_get_site_id());
  $form['eloqua']['elqDefaultTargetURL'] = _eloqua_form_hidden('');
  $form['eloqua']['elqPost'] = _eloqua_form_hidden('');
  $form['eloqua']['elqCustomerGUID'] = _eloqua_form_hidden('');
  $form['eloqua']['elqCookieWrite'] = _eloqua_form_hidden('0');

  // Add Javascript Init
  $form['eloqua']['script']['setting'] = array(
    '#type' => 'markup',
    '#value' => '<script type="text/javascript" language="JavaScript">var elqPPS="70";</script>',
  );
  $directory = variable_get(ELOQUA_VARIABLE_SCRIPTS_DIRECTORY, ELOQUA_VARIABLE_SCRIPTS_DIRECTORY_DEFAULT);
  $js_file = base_path() . $directory . '/elqScr.js';
  $form['eloqua']['script']['external'] = array(
    '#type' => 'markup',
    '#value' => '<script type="text/javascript" language="JavaScript" src="' . $js_file . '"></script>',
  );
  $initScript = <<<EOJS
<script type="text/javascript" language="JavaScript">
\$(document).ready(function() {
  if (GetElqCustomerGUID) {
    \$('#edit-elqCustomerGUID').val(GetElqCustomerGUID());
  }
});
// </script>
EOJS;
  $form['eloqua']['script']['init'] = array(
    '#type' => 'markup',
    '#value' => $initScript,
  );
  $user_headers = _eloqua_webform_get_user_headers();
  $form['eloqua']['user_headers'] = array(
    '#type' => 'hidden',
    '#default_value' => serialize($user_headers),
  );

  // Hooks that don't need to load up all the checks to see if said form
  // is eloqua_enabled
  foreach (module_implements('eloqua_form_alter') as $module_name) {
    $method = $module_name . '_eloqua_form_alter';
    $method($form, $form_state, $form_id);
  }
}