[Catalyst] Where should constraints go
John Siracusa
siracusa at mindspring.com
Fri Nov 3 19:07:45 GMT 2006
On 11/3/06, Ian Docherty <ian at iandocherty.com> wrote:
> Yes this pretty much agrees with my interpretation. It is not so much
> the location of the constraint rules as how to propagate them to the
> view (i.e the stash)
Do you mean for the purposes of client-side validation? Or do you
just mean how to display the (server-generated) error messages in the
view?
If you mean the latter, the way I do it is to pass in a form object as
a single parameter (usually named "form"). The form object itself has
a list of (possibly localized) error messages, as does each field
object contained in the form object. All of these messages are
generated (by a $form->validate() call) before the form object is
passed to the template.
In the template, there's a place for form-wide errors to appear (if
any) plus a place near each field for field-specific errors to appear.
IMO, all required data should already exist before anything is passed
to a template. The template should just decide where things should
go, possibly with minor massaging for visual purposes.
-John
More information about the Catalyst
mailing list