I am making an application using Zend Framework 2. I am validating input using it's InputFilter
. Is it possible, to make some Input
s required conditionally? I mean I have code like that:
$filter = new \Zend\InputFilter\InputFilter();
$factory = new \Zend\InputFilter\Factory();
$filter->add($factory->createInput(array(
'name' => 'type',
'required' => true
)));
$filter->add($factory->createInput(array(
'name' => 'smth',
'required' => true
)));
I want the field something
, to be required, ONLY when type
is equal 1
. Is there a built-in way to do that? Or should I just create custom validator?
isValid($value, array $context = [])
. That way,$context
can be used to enable/disable validation contextually. – Equation