diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index ff5ca11e338fa9597dcfb9a8ebe799e587e721ae..c2a149441c4ed8061189c23c2a9a71abc19b4ef0 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -681,7 +681,7 @@ class DynamicFormField extends VerySimpleModel { function setConfiguration($vars, &$errors=array()) { $config = array(); foreach ($this->getConfigurationForm($vars)->getFields() as $name=>$field) { - $config[$name] = $field->to_config($field->getClean()); + $config[$name] = $field->to_php($field->getClean()); $errors = array_merge($errors, $field->errors()); } diff --git a/include/class.forms.php b/include/class.forms.php index e0d1ea7416e98019e2d2122434e068aadeb8cf66..bbca68a9ccd74fe065285cec9f9f779cdbb1dd20 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -756,15 +756,17 @@ class FormField { } /** - * * to_config * * Transform the data from the value to config form (as determined by - * field). By default to_php is used at the base level - * + * field). to_php is used for each field returned from + * ::getConfigurationOptions(), and when the whole configuration is + * built, to_config() is called and receives the config array. The array + * should be returned, perhaps with modifications, and will be JSON + * encoded and stashed in the database. */ function to_config($value) { - return $this->to_php($value); + return $value; } /** @@ -2702,15 +2704,7 @@ class FileUploadField extends FormField { } function to_php($value) { - return JsonDataParser::decode($value); - } - - function to_config($value) { - - if ($value && is_array($value)) - $value = array_values($value); - - return $value; + return is_array($value) ? $value : JsonDataParser::decode($value); } function display($value) { @@ -3687,12 +3681,8 @@ class FreeTextField extends FormField { /* utils */ function to_config($config) { - - $keepers = array(); if ($config && isset($config['attachments'])) - foreach ($config['attachments'] as $fid) - $keepers[] = $fid; - + $keepers = $config['attachments'] = array_values($config['attachments']); $this->getAttachments()->keepOnlyFileIds($keepers); return $config;