diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index d7af7d9c5d10..86ae03888c8d 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1381,7 +1381,13 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $ } } else { - $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1)); + if (is_array($value) && count($value)) { + CRM_Utils_Array::formatArrayKeys($value); + $checkedValue = $value; + } + else { + $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1)); + } foreach ($customOption as $val) { if (in_array($val['value'], $checkedValue)) { if ($field['html_type'] == 'CheckBox') { @@ -1824,7 +1830,13 @@ public static function createTable($group) { */ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NULL) { $formattedGroupTree = array(); - $uploadNames = array(); + $uploadNames = $formValues = array(); + + // JSON encoded submitted form values passed via URL + $submittedValues = CRM_Utils_Request::retrieve('post', 'String'); + if (!empty($submittedValues)) { + $submittedValues = json_decode($submittedValues, TRUE); + } foreach ($groupTree as $key => $value) { if ($key === 'info') { @@ -1851,8 +1863,15 @@ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NU // add field information foreach ($value['fields'] as $k => $properties) { $properties['element_name'] = "custom_{$k}_-{$groupCount}"; + if (isset($submittedValues[$properties['element_name']])) { + $properties['element_value'] = $submittedValues[$properties['element_name']]; + } + elseif ($value = CRM_Utils_Request::retrieve($properties['element_name'], 'String', $form, FALSE, NULL, 'POST')) { + $formValues[$properties['element_name']] = $value; + } if (isset($properties['customValue']) && - !CRM_Utils_System::isNull($properties['customValue']) + !CRM_Utils_System::isNull($properties['customValue']) && + !isset($properties['element_value']) ) { if (isset($properties['customValue'][$groupCount])) { $properties['element_name'] = "custom_{$k}_{$properties['customValue'][$groupCount]['id']}"; @@ -1872,6 +1891,10 @@ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NU } if ($form) { + if (count($formValues)) { + $form->assign('submittedValues', json_encode($formValues)); + } + // hack for field type File $formUploadNames = $form->get('uploadNames'); if (is_array($formUploadNames)) { diff --git a/templates/CRM/common/customData.tpl b/templates/CRM/common/customData.tpl index 129e0555b518..5ba9f63567c9 100644 --- a/templates/CRM/common/customData.tpl +++ b/templates/CRM/common/customData.tpl @@ -54,6 +54,9 @@ {if $entityID} dataUrl += '&entityID=' + '{$entityID}'; {/if} + {if $submittedValues} + dataUrl += '&post=' + '{$submittedValues}'; + {/if} {literal} if (!cgCount) {