diff --git a/libraries/Util.php b/libraries/Util.php index 9048376cd9..c36520c1f4 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -4997,5 +4997,20 @@ class Util return $result; } + + /** + * Converts given (request) paramter to string + * + * @param mixed $value Value to convert + * + * @return string + */ + public static function requestString($value) + { + while (is_array($value) || is_object($value)) { + $value = reset($value); + } + return trim((string)$value); + } } diff --git a/libraries/config/FormDisplay.php b/libraries/config/FormDisplay.php index aeff097624..78da6b3174 100644 --- a/libraries/config/FormDisplay.php +++ b/libraries/config/FormDisplay.php @@ -639,12 +639,12 @@ class FormDisplay // cast variables to correct type switch ($type) { case 'double': - settype($this->_trimString($_POST[$key]), 'float'); + settype(Util::requestString($_POST[$key]), 'float'); break; case 'boolean': case 'integer': if ($_POST[$key] !== '') { - settype($this->_trimString($_POST[$key]), $type); + settype(Util::requestString($_POST[$key]), $type); } break; case 'select': @@ -660,7 +660,7 @@ class FormDisplay break; case 'string': case 'short_string': - $_POST[$key] = $this->_trimString($_POST[$key]); + $_POST[$key] = Util::requestString($_POST[$key]); break; case 'array': // eliminate empty values and ensure we have an array @@ -876,25 +876,10 @@ class FormDisplay private function _fillPostArrayParameters($post_values, $key) { foreach ($post_values as $v) { - $v = $this->_trimString($v); + $v = Util::requestString($v); if ($v !== '') { $_POST[$key][] = $v; } } } - - /* - * Converts given (request) paramter to string - * - * @param mixed $value Value to convert - * - * @return string - */ - private function _trimString($value) - { - while (is_array($value)) { - $value = reset($value); - } - return trim((string)$value); - } }