Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Multiple constraints for Data::FormValidator

by matthewb (Curate)
on Jul 29, 2004 at 11:55 UTC ( [id://378349]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Mulitple constraints for Data::FormValidator
in thread Mulitple constraints for Data::FormValidator

I had a similar problem yesterday (and found this thread while doing a bit of research) but found an alternative solution in the module docs and thought I'd write it up here for the next time someone searches.

From the docs:

Multiple constraints can be applied to a single field by defining the value of the constraint to be an array reference.

I needed to (sort of) check the validity of an email address and make sure that the address' owner was not already registered.

To complicate matters a bit further, I needed to check that the entry in a field to confirm the email address matched.

Here's an abridged version of the form profile I used. It presupposes the existence of a Class::DBI derived package that knows about users:

my $profile = { required => [ qw( user_name user_email user_email_confirm # more stuff here... ) ], msgs => { prefix => q[e_], constraints => { # helpful error messages: user_email_valid => q[Invalid address], user_email_lookup => q[Already registered], emails_match => q[Emails don't match], }, }, # tidy entries: filters => ['trim','strip'], constraints => { user_email => [ { name => q[user_email_valid], constraint => q[email], }, { name => q[user_email_lookup], constraint => sub { # have a look in database: !My::Content::User->search( user_email => $_[0], ); }, params => [ qw( user_email ) ], } ], user_email_confirm => { name => q[emails_match], constraint => sub { $_[0] eq $_[1] }, params => [ qw( user_email user_email_confirm ) ], }, # more constraints, perhaps... }, };

HTH someone,

MB

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found