Add GETPOSTISARRAY

This commit is contained in:
ATM john 2022-03-30 11:49:48 +02:00
parent 75d7c439dd
commit 16968b08f9
2 changed files with 27 additions and 2 deletions

View File

@ -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;

View File

@ -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']