I have a Form, which I create using the annotation builder like this:
$builder = new AnnotationBuilder();
$fieldset = $builder->createForm(new \Application\Entity\Example());
$this->add($fieldset);
$this->setBaseFieldset($fieldset);
In the controller everything is standard:
$entity = new \Application\Entity\Example();
$form = new \Application\Form\Example();
$form->bind($entity);
if($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if($form->isValid()) {
// save ....
}
}
The problem is, that $form->isValid() always returns true, even when empty or invalid form is submitted. What is even more weird is that the form element error messages are all set, hinting that they are not valid.
I have looked into the ZF2 Form / InputFilter / Input classes and found out that: Input->isValid() is called twice: once in the Form->isValid() and once in Form->bindValues() In the first call the validator chain in Input->isValid() ($this->getValidatorChain) is empty and in the second call (from bindValues) it is correct.
What may got wrong?
PS. Using devel version 2.1