diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a840dbd02b9..6e92714293b 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2131,8 +2131,7 @@ class ExtraFields } } elseif ($key_type == 'select') { // to detect if we are in search context - $value_arr_test = GETPOST($keysuffix."options_".$key.$keyprefix, 'none'); - if (is_array($value_arr_test)) { + if (GETPOSTISARRAY($keysuffix."options_".$key.$keyprefix)) { $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix, 'array:aZ09'); // Make sure we get an array even if there's only one selected $value_arr = (array) $value_arr; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f9672f776e5..9c268d31980 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -370,6 +370,32 @@ function GETPOSTISSET($paramname) return $isset; } +/** + * Return true if the parameter $paramname is submit from a POST OR GET as an array. + * Can be used before GETPOST to know if the $check param of GETPOST need to check an array or a string + * + * @param string $paramname Name or parameter to test + * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get) + * @return bool True if we have just submit a POST or GET request with the parameter provided (even if param is empty) + */ +function GETPOSTISARRAY($paramname, $method = 0) +{ + // for $method test need return the same $val as GETPOST + if (empty($method)) { + $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : ''); + } elseif ($method == 1) { + $val = isset($_GET[$paramname]) ? $_GET[$paramname] : ''; + } elseif ($method == 2) { + $val = isset($_POST[$paramname]) ? $_POST[$paramname] : ''; + } elseif ($method == 3) { + $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : ''); + } else { + $val = 'BadFirstParameterForGETPOST'; + } + + return is_array($val); +} + /** * Return value of a param into GET or POST supervariable. * Use the property $user->default_values[path]['createform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder']