isValid in zend framework form returns FALSE
Asked Answered
I

1

10

I have zend framework controller. In init method i create a form and fill the drop-down box with

$form = new FORM_NAME();
$form->getElement('ZdGroup')->addMultiOptions($zendesk_groups);

then in action i check

$formData = $this->getRequest()->getParams();
    if ($form->isValid($formData)) {
        ...
}

but isValid() returns FALSE if I delete this line $form->getElement('ZdGroup')->addMultiOptions($zendesk_groups); it return TRUE.

I don't understand why, does anybody have an idea?

Invariable answered 13/4, 2012 at 18:47 Comment(2)
We need your FORM_NAME() class to know what your form is doing.Elaboration
Maybe that element is set to required at FORM_NAME. $element->setRequired (true)?Vibratile
M
20

To answer the question of 'why', have you dumped the form error messages?

$form->getMessages(); //error messages
$form->getErrors(); //error codes
$form->getErrorMessages(); //any custom error messages

That might at least give you a better idea of 'why'.

Meteorite answered 14/4, 2012 at 3:5 Comment(4)
sometimes using file input without setting enctype on form , cause this problem .Encircle
umm.. are you sure? messages is empty and errors/errorMessage does not even exist as a functino.Maybellemayberry
@Blauhirn This question is 4 years old, pretty sure this answer is for ZF1.Meteorite
If i want for this in ZF3 then ?Larock

© 2022 - 2024 — McMap. All rights reserved.