[html-formfu] default values and submitted

Carl Franks fireartist at gmail.com
Tue Jul 22 20:17:30 BST 2008


2008/7/22 Andreas Marienborg <omega at palle.net>:
> Hey
>
> Stumbled upon something strange today.
>
> My pattern (pseudo) for most formfu things is this:
>
>
> sub create : bla FormEtc{
>
> my $obj : Stashed = $c->model->new({ parent => $c->req->param('parent') });
>
> $c->forward('doit');
>
> }
>
> sub edit : blah FormEtc {
>
>        my $obj : Stashed = $c->model->find($id);
>
> $c->forward('doit');
>
> }
>
> sub doit : blah {
>
>    if ($form->submitted_and_valid) {
>        $form->model()->update($obj);
>   }
> }
>
>
> now the problem is that for create where parent is set, results in
> submitted_and_valid triggering, can I prevent that somehow? if I set
> constraints on the form elements, they stop it, but this results in red
> boxes, which isn't really true, since its just showing the form for the
> first time.
>
> Or should I manually check for $c->req->method eq 'POST'?

I can't be sure, not knowing what fields you have, and what the form is for...
but you might be able to fix this by setting $form->indicator() to a
specific field name.
This will cause submitted_and_valid() to be true only when that named
field is submitted, rather than the default behaviour.

Carl



More information about the HTML-FormFu mailing list