[Catalyst] FormValidator usage / enhancements
Will Hawes
info at whawes.co.uk
Wed Dec 7 11:17:45 CET 2005
Carl Franks wrote:
> I'm experimenting with how best to use the FormValidator plug-in.
> I think it's far too complicated, particularly on pages where it's not
> appropriate to use it in conjunction with FillInForm and you actually
> have to use the API !
>
> What I've done at the moment is create a plug-in which subclasses
> Catalyst::Plugin::FormValidator and looks like this:
>
> package Catalyst::Plugin::FormValidator::MergeRequest;
> use strict;
> use NEXT;
> use base 'Catalyst::Plugin::FormValidator';
>
> sub form {
> my $c = shift;
>
> if (@_) {
> $c->NEXT::form( $c, @_ );
>
> # logic here
> # see below for discussion
> }
>
> return $c->{form};
> }
>
> 1;
>
> What I want the 'login' part to do is:
> For 'invalid' input, delete it from the request parameters.
> For 'valid' input, put it into the request parameters (because it may
> have been changed by FormValidator filters).
>
> To do this, is it "acceptable" to change values and delete keys from
> the hash-ref returned by $c->req->parameters() ? Will this break
> anything?
>
> I'm also unsure about 'unknown' input. As the Data::FormValidator docs
> say, "Whether or not this indicates an error in the user input is
> application dependant".
> Maybe add another method to optionally strip unknowns from the request
> parameters?
> $c->delete_unknown_params
>
> The purpose of this, is so only the 'auto' routine needs to deal with
> $c->form stuff such as invalid and valid
> The action routine can simply use $c->req->params as normal, assuming
> that all is well.
>
> Thoughts? Ideas?
>
> Carl
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
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.
Modifying c->req->params sounds like a recipe for disaster. If and when
it causes anything to break it will make debugging much harder.
More information about the Catalyst
mailing list