Index: trunk/core/kernel/utility/formatters/left_formatter.php =================================================================== diff -u -N -r5340 -r8842 --- trunk/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 5340) +++ trunk/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 8842) @@ -10,7 +10,6 @@ */ class kLEFTFormatter extends kFormatter { -//function Format($value, $options, &$errors) function Format($value, $field_name, &$object, $format=null) { if ( is_null($value) ) return ''; @@ -29,25 +28,40 @@ return $options['options'][$value]; } -//function Parse($value, $options, &$errors) + /** + * Parse value from form submit + * + * @param mixed $value + * @param string $field_name + * @param kDBItem $object + * @return mixed + */ function Parse($value, $field_name, &$object) { if ($value == '') return NULL; $options = $object->GetFieldOptions($field_name); - if( !array_search($value,$options['options']) ) - { - // required option is not defined in config => query for it - $db =& $this->Application->GetADODBConnection(); - $sql = sprintf($options['left_sql'],$options['left_key_field'],$options['left_title_field'],$value); - $found = $db->GetOne($sql); - if($found !== false) $options['options'][$found] = $value; + $found = isset($options['options']) && array_search($value, $options['options']); + if ($found !== false) { + // requested option found among field options + return $found; } - else - { - $found = array_search($value,$options['options']); + + // requested option is not found in field options -> query for it + $db =& $this->Application->GetADODBConnection(); + $sql = sprintf($options['left_sql'], $options['left_key_field'], $options['left_title_field'], $value); + $found = $db->GetOne($sql); + if ($found !== false) { + // option successfully retrieved from db -> cache it + $options['options'][$found] = $value; } - if($found === false) $found = $options['default']; + + if ($found === false) { + // option not found at all -> return not formatted value & set error + $object->SetError($field_name, 'invalid_option', 'la_error_InvalidOption'); + return $value; + } + return $found; } } \ No newline at end of file