You are here

function _pardot_form_collapse_form in Pardot Integration 7

Same name and namespace in other branches
  1. 6 pardot.module \_pardot_form_collapse_form()

Helper function to recurse through posted webform.

Parameters

array $tree: The post tree name => value pairs.

array $posted_values: The post tree, could be name => value pairs or index => value pairs.

array $form: The actual form structure of the form.

array $result: Return by reference re-structured tree that Pardot will leverage.

See also

_pardot_form_collapse()

1 call to _pardot_form_collapse_form()
_pardot_form_collapse in ./pardot.module
Collapses a submitted form into a flat array for Pardot.

File

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

Code

function _pardot_form_collapse_form($tree, $posted_values, $form, &$result) {
  foreach ($tree as $name => $value) {

    // Expand things in fieldsets.
    if (is_array($value) && !in_array($value, $posted_values)) {
      _pardot_form_collapse_form($value, $posted_values, $form[$name], $result);
    }
    elseif (is_array($value)) {

      // If it looks like a date, and the year is reasonable then use slashes
      // 0-1-2 = M/D/Y
      if (count($value) == 3 && $value[2] > 1900 && $value[2] < 2100 && checkdate($value[0], $value[1], $value[2])) {
        $result[$name] = implode('/', $value);
      }
      else {
        $result[$name] = implode(',', $value);
      }
    }
    elseif ($form[$name]['#type'] == 'select') {

      // Map select values to text versions. The numeric values won't mean
      // much to Pardot, CRM or any other integration.
      $result[$name] = $form[$name]['#options'][$value];
    }
    elseif (!empty($form[$name]['#addressfield'])) {
      if ($address = unserialize($value)) {
        foreach ($address as $address_field => $address_field_value) {
          if (empty($result[$address_field])) {
            $result[$address_field] = $address_field_value;
          }
        }
      }
    }
    else {
      $result[$name] = $value;
    }
  }
}