Hello,

I suggest you to extand Zend_Form with your own, let's call it App_Form.
But I do not recommend to override Zend_Form's getMessges() method, instead
I suggest to create new one, let's call it getMessagesFlatten() where you'll
implement necessary logic.

Or, if you don't need all features of Zend_Form extending, I think it's
better to re-write your jQuery plugin/script.


2010/2/8 David Mintz <[email protected]>:
> I am using a Zend_Form containing Zend_Form_Subform instances, and
> submitting via jQuery/Ajax, using the AjaxContext helper on the controller
> side. When validation fails, I am sending a JSON data structure with the
> validation errors and using a crude jQuery plugin of my own devise that
> displays the errors where they belong. Works fine for simple (subformless)
> forms, but I discovered that where there are subforms, $form->getMessages()
> (naturally enough) groups the error messages under the subform name, while
> my jQuery plugin is expecting a flat array of validation error messages. I
> could make my plugin smarter, I guess, but it seems simpler to do the work
> server side. So, I am ensuring unique array keys by prepending the form name
> to each field name:
>
>                 $messages = $form->getMessages();
>                 $validationErrors = array();
>                 foreach (array_keys($messages) as $name) {
>                     foreach($messages[$name] as $k => $v) {
>                         $validationErrors["{$name}_{$k}"] = $v;
>                     }
>                 }
>                 $this->view->assign(array('validationErrors' =>
> $validationErrors));
>
> Seems to work fine. Any comments so far?
>
> But! This is going to happen in various places around the application, so I
> am considering the best approach. A controller action helper that mangles
> $form->getMessages() for me? Or have all my complex forms extend a base
> class that overrides getMessages()? Or... ?
>
> Thanks.
>
> --
> Support real health care reform:
> http://phimg.org/
>
> --
> David Mintz
> http://davidmintz.org/
>
>
>



-- 
Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 617 179 344
Homepage: http://www.ixti.ru
JID: [email protected]

*Origin: Happy Hacking!

Reply via email to