Form via AnnotationBuilder in extended form doesn't use validators and filters #4220

jirinapravnik opened this Issue Apr 13, 2013 · 3 comments

4 participants


I create form via AnnotationBuilder and I want to add new elements to it. I can use it in controller and add new elements there. But it's not nice approach to add new elements in the controller and it's better add them in the extended form. Inputs are added sucessfuly, but filters and validators don't wok.


use Zend\Form\Annotation as Form;
 * @Form\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
class Category {

     * @Form\Type("Zend\Form\Element\Hidden");
    protected $id;

     * @Form\Required(true)
     * @Form\Filter({"name" : "StringTrim"})
    protected $name;   


class Edit extends Form {

    public function __construct() {

        $builder = new AnnotationBuilder();
        $form = $builder->createForm(new Category());

                    'type' => 'submit',
                    'name' => 'save'

In controller:

$form = new Edit();

Return always true (even if the name element is empty).


you should use * @Annotation\Filter({"name":"StringTrim"})


It is not that problem, I have Form\Annotation namespace as: use Zend\Form\Annotation as Form; . I updated issue

Zend Framework member

Not able to reproduce this. I aped one of the existing tests in AnnotationBuilderTest (and it's annotated form) to verify it:

public function testInputFilterAnnotationsActuallyWork()
    $entity = new TestAsset\Annotation\EntityWithInputFilterAnnotation();
    $builder = new Annotation\AnnotationBuilder();
    $form = $builder->createForm($entity);
    $inputFilter = $form->getInputFilter();

    $this->assertCount(2, $inputFilter->get('username')->getValidatorChain());
    $this->assertCount(1, $inputFilter->get('password')->getValidatorChain());

    $form->setData(['username' => '', 'password' => '']);

    $form->setData(['username' => '123456', 'password' => '']);

@Maks3w this can be closed

@Maks3w Maks3w closed this Oct 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment