Trying to pass a closure into filter_var_array(), but can't seem to make it work.
$clean = function( $html ) {
return HTML::sanitize( $html, array('p','ul','ol','li'), array('class','style') );
};
$args = array( 'filter' => FILTER_CALLBACK, 'options' => $clean );
$fields = filter_var_array(
array( $_POST['field1'], $_POST['field2'], $_POST['field3'] ),
array( 'field1' => $args, 'field2' => $args, 'field3' => $args )
);
After the above is run, $fields is an empty array.
Note, individual filtering works fine:
$field1= filter_var( $_POST['field1'], FILTER_CALLBACK, array( 'options' => $clean ) );
Any ideas?
You are passing in the values of $_POST
without their keys, hence no callbacks will be triggered. Just pass in the entire $_POST
array instead, e.g.
$fields = filter_var_array(
$_POST,
array(
'field1' => $args,
'field2' => $args,
'field3' => $args
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With