You are here

function pardot_footer in Pardot Integration 6

Implementation of hook_footer().

File

./pardot.module, line 168
ParDot integration module.

Code

function pardot_footer() {

  // Add site javascript.
  drupal_add_js(theme('pardot_js'), 'inline', 'footer');
  $output = '';
  if (isset($_SESSION['pardot_submission'])) {
    $submission = pardot_submission_load($_SESSION['pardot_submission']);

    // Update Post Data
    $submission->status = PARDOT_STATUS_UPLOADED;
    pardot_submission_save($submission);
    $form_settings = pardot_webform_load($submission->form_nid);
    $url = $form_settings->url;
    $post_fields = $submission->data['post_fields'];

    // Map fields to their Pardot values.
    foreach ($post_fields as $key => $value) {
      if (!empty($form_settings->data[$key])) {
        $result[$form_settings->data[$key]['key']] = $value;
      }
      else {
        $result[$key] = $value;
      }
    }
    $url = url($form_settings->url, array(
      'query' => $result,
    ));
    $output .= '<iframe src="' . $url . '" width="1" height="1"></iframe>';
    unset($_SESSION['pardot_submission']);
  }
  return $output;
}