You are here

function pardot_page_build in Pardot Integration 7

Implements hook_page_build().

File

./pardot.module, line 198
Pardot integration module.

Code

function pardot_page_build(&$page) {
  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,
    ));
    $page['page_bottom']['pardot'] = array(
      '#type' => 'markup',
      '#markup' => '<iframe src="' . $url . '" width="1" height="1"></iframe>',
    );
    unset($_SESSION['pardot_submission']);
  }
}