note 128821 added to function.filter-input-array
| From: | cornelyu85.yahoo.com via php-notes | Date: | Tue, 22 Aug 2023 16:26:18 +0000 |
| Subject: | note 128821 added to function.filter-input-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220783@lists.php.net to get a copy of this message | ||
Here's an extended function that allows you to keep also the unfiltered items/args from the
request, while you also apply validation to some of them:
<?php
$validationRules = [
'foo' => [
'filter' => FILTER_VALIDATE_REGEXP,
'options' => ['regexp' => '/^(bar|baz)$/i']
]
];
$request = filter_input_array_keep_unfiltered_args(INPUT_POST, $validationRules);
var_dump($request);
function filter_input_array_keep_unfiltered_args($type, $filters, $addEmpty = true)
{
$rawRequest = filter_input_array($type);
$validationRules = [];
foreach ($rawRequest as $key => $value) {
$validationRules[$key] = isset($filters[$key]) ? $filters[$key] : ['filter' =>
FILTER_DEFAULT];
}
return filter_input_array($type, $validationRules, $addEmpty);
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 86.120.59.66)
----
Manual Page -- https://php.net/manual/en/function.filter-input-array.php
Edit -- https://main.php.net/note/edit/128821
Del: integrated -- https://main.php.net/note/delete/128821/integrated
Del: useless -- https://main.php.net/note/delete/128821/useless
Del: bad code -- https://main.php.net/note/delete/128821/bad+code
Del: spam -- https://main.php.net/note/delete/128821/spam
Del: non-english -- https://main.php.net/note/delete/128821/non-english
Del: in docs -- https://main.php.net/note/delete/128821/in+docs
Del: other reasons-- https://main.php.net/note/delete/128821
Reject -- https://main.php.net/note/reject/128821
Search -- https://main.php.net/manage/user-notes.php