Skip to content

Commit

Permalink
CRM-18427: Submitted custom data values not reloaded on form when val…
Browse files Browse the repository at this point in the history
…idation fails
  • Loading branch information
monishdeb committed Jul 22, 2016
1 parent a4a6af6 commit fb56e96
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 26 additions & 3 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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') {
Expand All @@ -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']}";
Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions templates/CRM/common/customData.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
{if $entityID}
dataUrl += '&entityID=' + '{$entityID}';
{/if}
{if $submittedValues}
dataUrl += '&post=' + '{$submittedValues}';
{/if}
{literal}

if (!cgCount) {
Expand Down

0 comments on commit fb56e96

Please sign in to comment.