0
votes

I have an issue when adding a filter to my select elements in Zend 2.2. When creating a select element, a default validator is added to this element:

This element adds an InArray validator to its input filter specification in order to validate on the server if the selected value belongs to the values.

This works fine until I add a custom filter to that element:

$filter = new Input('element_name');
$filter->setRequired(true);
$this->add($filter);

This Zend\InputFilter\Input is added to a Zend\InputFilter\InputFilter which is later added to my form. From now on the default validator is lost.

How can I add a filter to form elements without losing their default validators?

Am I missing something? I don't expect this as the default behaviour, because everyone is desperately asking how to deactivate it. There's even an attribute to deactivate it ('disable_inarray_validator'), however, I want to keep that validator without passing all my entries of the selectbox to my InputFilter. Also I didn't find anything in the Zend 2 documentation. I guess the solution must be something simple. Thanks in advance.

Note: Same happens when I add the InputFilter with the InputFilterManager to the form.

1
Would love to know the answer to this too. I spent quite a few hours trying to get this to work. I tried using the form manager to get the form in my controller rather than instantiating the form directly. Also tried adding my fields in init() method rather than the __construct. Tried creating input filters in mutiple ways, used $factory->createInput in my input filters. Also tried using the $form->setPreferFormInputFilter() method with no success. Seems like a bug or I am missing something. Please post answer if you find onePurple Hexagon

1 Answers

0
votes

Please see my comment on your question first. Only thing I thought might work that I haven't tried to get this to work is:

$input->getFilterChain()
      ->attachByName('stringtrim')

or

$input->getFilterChain()
    ->attach(new StringTrim())