function _wf_crm_form_data in Webform CiviCRM Integration 7.3
Dispatch function to fill data array with submitted form values Called during webform submission
Parameters
$data: Array of crm data
$enabled: Array of crm webform fields
$submission: Webform submission array
$updating: Array of known contact ids
$node: Node object
1 call to _wf_crm_form_data()
- wf_crm_process_submission in ./
webform_civicrm_forms.inc - Webform submission handler Create/update CiviCRM contacts and related data Called by presave, insert and update webform hooks
File
- ./
webform_civicrm_forms.inc, line 1555
Code
function _wf_crm_form_data(&$data, $enabled, $submission, $updating, $node) {
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
$fields = wf_crm_get_fields();
foreach ($enabled as $field_key => $fid) {
$val = wf_crm_sub_value($submission, $fid);
if ($val !== FALSE) {
list(, $c, $ent, $n, $table, $name) = explode('_', $field_key, 6);
// Fieldsets and existing contact fields are not CRM data, so ignore
if ($name === 'existing' || $name === 'fieldset') {
continue;
}
// Ignore values from fields hidden by existing contact component
if ($ent == 'contact' && isset($enabled["civicrm_{$c}_contact_1_contact_existing"])) {
$component = $node->webform['components'][$enabled["civicrm_{$c}_contact_1_contact_existing"]];
$existing_contact_val = wf_crm_sub_value($submission, $component['cid']);
// Fields should be hidden if value is empty (no selection) or a numeric contact id
if (!$existing_contact_val[0] || is_numeric($existing_contact_val[0])) {
$type = $table == 'contact' && strpos($name, 'name') ? 'name' : $table;
if (in_array($type, $component['extra']['hide_fields'])) {
// Remove the value from the webform submission
wf_crm_sub_value($submission, $fid, array(
NULL,
));
continue;
}
}
}
$field = $fields[$table . '_' . $name];
// Ignore values from hidden fields
if ($field['type'] == 'hidden') {
continue;
}
// Translate privacy options into seperate values
if ($name === 'privacy') {
foreach (array_keys(wf_crm_exposed_options($node, $fid)) as $key) {
$data[$ent][$c][$table][$n][$key] = in_array($key, $val);
}
continue;
}
if (!empty($field['extra']['multiple'])) {
// Merge with existing data
if (!empty($data[$ent][$c][$table][$n][$name]) && is_array($data[$ent][$c][$table][$n][$name])) {
$val = array_unique(array_merge($val, $data[$ent][$c][$table][$n][$name]));
}
// Implode data that will be stored as a string
if ($table !== 'other' && $name !== 'event_id' && $table !== 'contact' && wf_crm_aval($field, 'data_type') != 'ContactReference') {
$val = $sp . implode($sp, $val) . $sp;
}
}
elseif ($name === 'image_URL') {
if (empty($val[0]) || !($val = wf_crm_filepath($val[0]))) {
continue;
}
}
elseif ($field['type'] === 'date') {
$val = empty($val[0]) ? '' : str_replace('-', '', $val[0]);
// Add time field value
$time = wf_crm_aval($data, "{$ent}:{$c}:{$table}:{$n}:{$name}", '');
// Remove default date if it has been added
if (strlen($time) == 14) {
$time = substr($time, -6);
}
$val .= $time;
}
else {
$val = isset($val[0]) ? $val[0] : '';
}
// Fudge together date and time fields
if ($field['type'] === 'time' && substr($name, -8) === 'timepart') {
$name = str_replace('_timepart', '', $name);
// Add date (default to today)
$date = wf_crm_aval($data, "{$ent}:{$c}:{$table}:{$n}:{$name}", date('Ymd'));
$val = $date . str_replace(':', '', $val);
}
// Only known contacts are allowed to empty a field
if ($val !== '' && $val !== NULL || !empty($updating['cid'][$c])) {
$data[$ent][$c][$table][$n][$name] = $val;
}
}
}
}