[Html-widget] How to detect valid _and_ submitted?

Carl Franks fireartist at gmail.com
Fri Sep 8 12:01:13 CEST 2006

On 08/09/06, Tobias Kremer <t at funkreich.de> 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.


More information about the Html-widget mailing list