Skip to content

Commit

Permalink
store/fetch the submitted data to/form cache
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Jul 22, 2016
1 parent fb56e96 commit f22fdc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,12 @@ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NU
$formattedGroupTree = 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);
// retrieve qf key from url
$qfKey = CRM_Utils_Request::retrieve('qf', 'String');

// fetch submitted custom field values later use to set as a default values
if ($qfKey) {
$submittedValues = CRM_Core_BAO_Cache::getItem('custom data', $qfKey);
}

foreach ($groupTree as $key => $value) {
Expand Down Expand Up @@ -1863,12 +1865,12 @@ 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')) {
if ($value = CRM_Utils_Request::retrieve($properties['element_name'], 'String', $form, FALSE, NULL, 'POST')) {
$formValues[$properties['element_name']] = $value;
}
elseif (isset($submittedValues[$properties['element_name']])) {
$properties['element_value'] = $submittedValues[$properties['element_name']];
}
if (isset($properties['customValue']) &&
!CRM_Utils_System::isNull($properties['customValue']) &&
!isset($properties['element_value'])
Expand All @@ -1892,7 +1894,9 @@ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NU

if ($form) {
if (count($formValues)) {
$form->assign('submittedValues', json_encode($formValues));
$qf = $form->get('qfKey');
$form->assign('qf', $qf);
CRM_Core_BAO_Cache::setItem($formValues, 'custom data', $qf);
}

// hack for field type File
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/common/customData.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
{if $entityID}
dataUrl += '&entityID=' + '{$entityID}';
{/if}
{if $submittedValues}
dataUrl += '&post=' + '{$submittedValues}';
{if $qf}
dataUrl += '&qf=' + '{$qf}';
{/if}
{literal}

Expand Down

0 comments on commit f22fdc2

Please sign in to comment.