zend-inputfilter icon indicating copy to clipboard operation
zend-inputfilter copied to clipboard

Inputfilter getValues() returns the field which is not in input data

Open metanav opened this issue 9 years ago • 5 comments

$specs =  array(
    'title' => array(
        'name'       => 'title',
        'filters' => array(
            array(
                'name' => 'Zend\Filter\StringToLower',
            ),
        ),
    ),
);

$inputFilterFactory = new \Zend\InputFilter\Factory();
$inputFilter = $inputFilterFactory->createInputFilter($specs);
$data = array(
    'title' => 'TEST',
);
$inputFilter->setData($data);
var_dump($inputFilter->getValues());

Expected Output:

array(1) {
  ["title"]=>
  string(3) "test"
}
$data = array(
    'xyz' => 'something',
);
$inputFilter->setData($data);
var_dump($inputFilter->getValues());

Unexpected (or it is intentional?) Output:

array(1) {
  ["title"]=> NULL
}

metanav avatar Sep 05 '15 16:09 metanav

Related to https://github.com/zendframework/zf2/issues/7440

Maks3w avatar Sep 05 '15 16:09 Maks3w

One possible option is to add an argument to getValues() for to return all inputs or only the inputs with data set.

Maks3w avatar Sep 05 '15 16:09 Maks3w

Another option is add a new method for return only the fields with data (method name is more expressive rather than arguments values).

Maks3w avatar Sep 05 '15 16:09 Maks3w

That would not stop input filter to do filtering of the input which is not set. The new method would just do one more filtering of unset data.

metanav avatar Sep 05 '15 16:09 metanav

This repository has been closed and moved to laminas/laminas-inputfilter; a new issue has been opened at https://github.com/laminas/laminas-inputfilter/issues/9.

weierophinney avatar Dec 31 '19 21:12 weierophinney