Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions includes/wf_crm_webform_postprocess.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
* @see webform_civicrm_webform_submission_presave
* @param stdClass $submission
*/
public function preSave(&$submission) {
public function preSave(&$submission, $formatDate = FALSE) {
$this->submission = &$submission;
$this->data = $this->settings['data'];
// Check for existing submission
Expand All @@ -122,7 +122,7 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
return;
}

$this->fillDataFromSubmission();
$this->fillDataFromSubmission($formatDate);

// Create/update contacts
foreach ($this->data['contact'] as $c => $contact) {
Expand Down Expand Up @@ -2312,7 +2312,7 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
/**
* Fill data array with submitted form values
*/
private function fillDataFromSubmission() {
private function fillDataFromSubmission($formatDate = FALSE) {
foreach ($this->enabled as $field_key => $fid) {
$val = $this->submissionValue($fid);
// If value is null then it was hidden by a webform conditional rule - skip it
Expand Down Expand Up @@ -2376,6 +2376,10 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
$time = substr($time, -6);
}
$val .= $time;
if ($formatDate) {
$val = new DateTime($val);
$val = $val->format('YmdHis');
}
}
// The admin can change a number field to use checkbox/radio/select/grid widget and we'll sum the result
elseif ($field['type'] === 'number') {
Expand Down
20 changes: 19 additions & 1 deletion webform_civicrm.module
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,26 @@ function webform_civicrm_webform_component_info() {
function webform_civicrm_webform_submission_presave($node, &$submission) {
if (!empty($node->webform_civicrm)) {
module_load_include('inc', 'webform_civicrm', 'includes/wf_crm_webform_postprocess');

$formatDate = FALSE;
foreach ($node->webform['components'] as $component) {
if (strpos($component['form_key'], 'civicrm_') === 0 && strpos($component['form_key'], '_custom_')) {
// custom field
$form_key_items = explode('_', $component['form_key']);
$custom_field_id = array_pop($form_key_items);
civicrm_initialize();
$result = civicrm_api3('CustomField', 'getSingle', [
'sequential' => 1,
'id' => $custom_field_id,
]);
if ($result['data_type'] == 'Date') {
$formatDate = TRUE;
}
}
}

$processor = wf_crm_webform_postprocess::singleton($node);
$processor->preSave($submission);
$processor->preSave($submission, $formatDate);
}
}

Expand Down