jterry jterry - 4 months ago 59
PHP Question

POST Variable Array and filter_input

While using

filter_input
, I'm not able to pull in a
POST
array variable. The
POST
input:

type => 'container',
action => 'edit',
data[display] => 1,
data[query_limit] => 100


Directly accessing the superglobal, I can pull in the
data
variable correctly as an array, but using the
filter_input
function, nothing is returned:

$data = $_POST['data']; // Working, woot
$data = filter_input(INPUT_POST, 'data'); // returns null, should return array
$action = filter_input(INPUT_POST, 'action'); // returns "edit" (correctly)


Is it not possible to use
filter_input
for a
POST
array variable?

Answer

Try :

$data   = filter_input(INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);