how to use filter_input NO $_POST

Asked

Viewed 682 times

0

Good use the filter_input thus:

filter_input(INPUT_POST, 'nome_input', FILTER_SANITIZE_SPECIAL_CHARS);

I wonder how I can use it in $_POST for all input, without giving the name.

1 answer

1

Just get all the field names with the function array_keys and iterate on them:

foreach(array_keys($_POST) as $var)
{
    $filtered[$var] = filter_input(INPUT_POST, $var, FILTER_SANITIZE_SPECIAL_CHARS);
}

In this way, $filtered will have all the values of $_POST after passing through the filter.

You can alternatively use the function array_map:

$filtered = array_map(function ($var) {
    return filter_input(INPUT_POST, $var, FILTER_SANITIZE_SPECIAL_CHARS);
}, $_POST);
  • Still my netbeans is asked to use the filter on $_POST. Following photo for you understand better. http://i.imgur.com/a6ZLZbv.png

Browser other questions tagged

You are not signed in. Login or sign up in order to post.