You can use the method setValidationGroup inside the InputFilter class to set what input fields should be validated.
You could for example extend the InputFilter class and use the setValidationGroup in a customized setData method, and set the group depending on the presence of a certain field in $data.
For example something like this:
<?php
namespace Application\InputFilter;
use Zend\InputFilter\InputFilter;
class CustomInputFilter extends InputFilter
{
/**
* Set data to use when validating and filtering
*
* @param array|Traversable $data
* @return InputFilterInterface
*/
public function setData($data)
{
$group = array(
// your custom validation group
);
if(isset($data['fieldName'])){
$this->setValidationGroup($group);
}
// Forward to default setData method
return parent::setData($data);
}
}
Extending the class is just one option to show what is possible. You can of course also setValidationGroup somewhere else externally without a customizing the InputFilter class.
$group = array(
// your custom validation group
);
$inputFilter->setValidationGroup($group);