[Catalyst] FormValidator usage / enhancements
Bill Moseley
moseley at hank.org
Wed Dec 7 14:04:31 CET 2005
On Wed, Dec 07, 2005 at 11:31:49AM +0000, Carl Franks wrote:
> On 07/12/05, Will Hawes <info at whawes.co.uk> wrote:
> >
> > I'm not sure I understand what you're trying to do, but you should
> > probably consider making a copy of $c->req->params locally if you want
> > to modify it.
>
> What I'm trying to do is make FormValidator transparent; to allow my
> 'action' routine and any other plugins etc, to be able to access the
> input as usual, via $req->params
>
> I don't want all of the 'action' routines to have to check
> $c->form->missing, $c->form-->valid, etc.
Do you have more than one action routine handling the same form?
Doesn't the existence of a single invalid parameter mean the entire
form is invalid? If so, then the entire form needs to be shown again,
with sticky values -- including even the invalid ones? So you
wouldn't want to delete the invalid parameters. And seems you could
catch that in one place.
My form handling actions look something like:
sub edit : Local {
my ( $self, $c, $id ) = @_;
my $form = MyApp::Forms::User->new( $id );
$form->update_from_params( $c )
if $c->form_posted;
}
If I'm not updating the database and instead need the parameters in my
controller (and need them as modified by the form) then its:
sub edit : Local {
my ( $self, $c ) = @_;
my $form = MyApp::Forms::User->new;
if ( $c->form_posted && $form->validated( $c ) ) {
my $date = $form->field( 'date' )->value;
}
}
So I'm not using $c->req->params in my code, but the values returned
in the "form".
--
Bill Moseley
moseley at hank.org
More information about the Catalyst
mailing list