The Zend\InputFilter\Input
class has another parameter continue_if_empty
which when used in combination with required
and allow_empty
will do what you need.
You can either set the param directly on the input filter element using the setContinueIfEmpty()
method
$elementA->setRequired(true);
$elementA->setAllowEmpty(true);
$elementA->setContinueIfEmpty(true);
Or, you can do the same by setting values in your input filter specification
$inputFilter->add([
'name' => 'elementA',
'required' => true,
'allow_empty' => true,
'continue_if_empty' => true,
'filters' => [
//..
],
'validators' => [
//..
],
]);
Basically the above says this value must be present and may be empty, but if it is, validate it anyway.