[Catalyst] FormValidator usage / enhancements

Carl Franks fireartist at gmail.com
Wed Dec 7 11:02:29 CET 2005


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



More information about the Catalyst mailing list