diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 3a445717776c6f44ff6cab59ba717d0fe79876b4..94b9b786e76c6cff6afede8f44f12ba509939cdd 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1122,9 +1122,15 @@ class SelectionField extends FormField { } function to_php($value, $id=false) { - $value = ($value && !is_array($value)) - ? JsonDataParser::parse($value) : $value; + if (is_string($value)) + $value = JsonDataParser::parse($value) ?: $value; + if (!is_array($value)) { + $config = $this->getConfiguration(); + if (!$config['multiselect']) { + // CDATA may be built with comma-list + list($value,) = explode(',', $value, 2); + } $choices = $this->getChoices(); if (isset($choices[$value])) $value = array($value => $choices[$value]); diff --git a/include/class.forms.php b/include/class.forms.php index 6e2ddffc84313ffc547ceb0387eff3c9d7c49a75..c80c34ba1567cea62f7cb38150e11b020ca39228 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -950,16 +950,22 @@ class ChoiceField extends FormField { else $array = $value; $config = $this->getConfiguration(); - if (is_array($array) && !$config['multiselect'] && count($array) < 2) { - reset($array); - return key($array); + if (!$config['multiselect']) { + if (is_array($array) && count($array) < 2) { + reset($array); + return key($array); + } + if (is_string($array) && strpos($array, ',') !== false) { + list($array,) = explode(',', $array, 2); + } } return $array; } function toString($value) { $selection = $this->getChoice($value); - return is_array($selection) ? implode(', ', array_filter($selection)) + return is_array($selection) + ? (implode(', ', array_filter($selection)) ?: $value) : (string) $selection; }