In a project I have a huge form -- with many fields, nested fieldsets, collections etc. The form validation is failing and I don't know, why.
How should such a problem be handled? What is a good, efficient approach to find out, why a form validation is failing?
I finally found a way to detect the validation error(-s) without to debug every (sub-sub-sub-)fieldset and every (sub-sub-sub-)element. It's simple $form->getMessages()
. Or alternatively $this->FormElementErrors($form)
in the view script.
Did I know about this methods before? Sure, I did. But I was unconcerned about the manner, how it works, and the property messages
led me astray:
When I got validation issues, I set a breakpoint somewhere after the Zend\Form#isValid()
call and saw then in Xdebug, that Zend\Form#messages
property was empty. And I was surprised about it, because a property "messages" suggests, that it will contain (validation error) messages. This logic applies to in Element
s -- and a Form
actually is an Element
(since Form
extends
Fieldset
extends
Element
).