Simple way to add a filter to Zend-InputFilter
Using Zend-InputFilter is remarkably easy to use: use Zend\InputFilter\Factory as InputFilterFactory; // set up InputFilter $specification = [ 'my_field' => [ 'required' => false, 'filters' => [ ['name' => 'StringTrim'], ], ], ]; $factory = new InputFilterFactory(); $inputFilter = $factory->createInputFilter($specification); // use InputFilter on some data $data['my_field] = 'Some string'; $inputFilter->setData($data); if ($inputFilter->isValid()) { Return false; } return $inputFilter->getValues(); // my_field is now trimmed How do you add your filter to it though? This is… continue reading.