logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: How to detect valid _and_ submitted?: msg#00013

Subject: Re: How to detect valid _and_ submitted?
On 08/09/06, Tobias Kremer <t@xxxxxxxxxxxx> wrote:
> >   $c->forward( 'do_it' ) if !$c->widget_result( 'my_form' )->has_errors &&
> >     $c->request->param( $w->indicator );
>
> Of course, the following also works but still looks too verbose IMHO:
>
>   if( !$c->widget_result( 'my_form' )->has_errors
>     && $c->widget_result( 'my_form' )->is_valid ) {
>     $c->forward( 'do_it' );
>   }

Logically, I would do it that way, but make it a bit clearer:

my $form = $c->widget_result( 'my_form' );
if ( $form->valid && ! $form->errors ) {
    $c->forward( 'do_it' );
}

As long, as you're using $w->indicator(), then valid() will only be
true after a form submission.

> Wouldn't it make sense to add this to HTML::Widget::Result as
> something like a valid_and_submitted() method?

Whether it's submitted is more a function of C::P::H::W, and what it
does with indicator(), which can be a field name or a sub-ref.
If you really want a single methodname for this, you could just add it
to the base of your Cat app.

Carl


<Prev in Thread] Current Thread [Next in Thread>