[Catalyst] "Best Practice" for validating form input
Kevin Old
kevinold at gmail.com
Thu Aug 25 21:42:41 CEST 2005
On 8/1/05, Bill Moseley <moseley at hank.org> wrote:
> On Mon, Aug 01, 2005 at 04:19:14PM -0400, Sean Davis wrote:
> > In CGI::App, I typically had a form submit back to itself and them used
> > something like ->forward (an "internal redirect") to move to the next page
> > if the form validated. Using URL mapping, one needs to do a real redirect.
> > I'm just curious what peoples' thoughts are on an idiom that works for
> > Catalyst, as the two-queries per page (one to collect data, and the second
> > to do a redirect after the data is validated) seems slightly tedious for
> > many cases.
>
> I'm new too all this, too. Here's what I'm doing in one controller --
> I'll post in hopes someone can point out what I could do better.. ;)
[snip]
> if ( $form->has_missing || $form->has_invalid ) {
> $c->stash->{message} = 'Fix the form, will ya!';
> $c->stash->{errors} = $form->msgs;
> return $c->forward('edit');
> }
[snip]
Hi Bill,
Thanks for the example above. I am implementing this too, and was
wondering if you have any code showing how you display $form->msgs. I
see they are a hash of <span> tags, but wondering if there was another
option in displaying them other than just looping through the hash and
printing the <span>'s.
Specifically, I'd like to have the <span> placed beside the field that
had the problem. One thing I thought about is using some JS to add
the <span> after the element with the error.
The only thing is I'm dealing with a "conditional" form. By that I
mean that I have 20 questions/form elements over all and rather than
coding a multi-page form, I have some JavaScript that displays the
appropriate question, based on that question, the next, and so on.
So, I might just need to display the <span>'s at the top of the page.
Either way, I'd like to know if you (or anyone on the list) has the
<span>'s displaying next to the field with the error.
Any help is greatly appreciated,
Kevin
--
Kevin Old
kevinold at gmail.com
More information about the Catalyst
mailing list