Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Data::FormValidator, Not

by impossiblerobot (Deacon)
on Sep 19, 2002 at 17:37 UTC ( [id://199231]=note: print w/replies, xml ) Need Help??


in reply to Data::FormValidator, Not

Unfortunately, at this time you cannot pass a CGI object into Data::FormValidator. You must pass a reference to a hash containing your form data, which you can easily get by calling:

my $formdata = $q->Vars; my ($valids, $missings, $invalids, $unknowns) = Data::FormValidator->validate($formdata, $profile);

Oddly enough, I just finished writing a patch to D:FV that would allow passing a CGI object; I just haven't gotten around to submitting it to the module maintainer (markjugg).


Impossible Robot

Replies are listed 'Best First'.
Re: Re: Data::FormValidator, Not
by sz (Friar) on Sep 19, 2002 at 18:04 UTC
    Thanks so much! It works fine now. I don't know where I got the idea that I could pass a CGI object. I've probably gotten too used to that convenience with other modules I use.

    Your patch would make a great addition!

    sz
Re^2: Data::FormValidator, Not
by Aristotle (Chancellor) on Sep 19, 2002 at 20:21 UTC
    Of course, you can skip the temporary variable using
    my ($valids, $missings, $invalids, $unknowns) = Data::FormValidator->validate( scalar($q->Vars), $profile);
    Do those couple extra characters warrant a patch? Shrug.. Well, YMMV. Update: it obviously does - something new learned for the day.

    Makeshifts last the longest.

      Although eliminating the temporary variable would work for the simplest case, Data::FormValidator does more than just validate data; it also applies filters to the data. Without the temporary variable, you're throwing away your filtered data.

      Therefore, the need for the patch: to filter the CGI object data directly, rather than in a separate data structure. :-)


      Impossible Robot
Re: Re: Data::FormValidator, Not
by markjugg (Curate) on Dec 23, 2002 at 15:20 UTC
    impossiblerobot, I'll be interested to see your patch. One 'gotcha' with using the direct CGI object is that it supports multiple values for a single variable. Data::FormValidator does not currently support this, though perhaps it should.

    To provide that functionality, we have to figure out if all the values should receive the same validation (that seems reasonable), and how we report the errors if some values fail but not others.

    Then to be consistent, we should probably also support a way to have multi-values when passing a regular hash, perhaps with a key that points to an array reference containing multiple values.

    -mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://199231]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found