-- Steven <
gatecrasher1981@...> wrote
(on Thursday, 08 May 2008, 06:04 PM +0100):
> > > How would you go about displaying a custom error message when a sub
> > > form fails validation? i.e. I've overloaded the subform's isValid()
> > > method to add some custom validation thats reliant on a combination of
> > > all the fields in the subform, if this fails I'd like to pass an error
> > > message to surround the subform as with individual form elements.
> >
> > Use the sub form's description:
> >
> > $subForm->setDescription($errorMessage);
> > $subForm->setDecorators(array(
> > 'FormElements',
> > array('Description', array('placement', 'prepend')),
> > 'Fieldset',
> > 'DtDdWrapper',
> > ));
> >
>
> Excellent thanks!
>
> Although this is only my first attempt at using Zend_Form maybe future
> releases would benefit from some kind of mechanism for grouping fields
> together with a particular mind to validation? Almost like extending
> the display group functionality?
Extending the "sub form" functionality makes more sense, as they are
supposed to be used for logical groupings (validation falls under this
category).
Unfortunately, I have yet to see a use case that can be generalized for
this; in most cases, extending Zend_Form_SubForm and overriding
isValid() appears to make the most sense, as it allows the developer to
customize for the form's particular needs. I am, however, open to adding
such capability if the community can present a good, common use case.
> Please correct me if I'm missing some kind of functionality, the
> flexibility in the component is a little overwhelming :-)
It's a complex component - many areas of responsibility. I'm happy that
you're mostly discovering what you need to do, however.
--
Matthew Weier O'Phinney
Software Architect |
matthew@...
Zend - The PHP Company |
http://www.zend.com/