Now, lets say I have a sign-up form. If somebody is signing up I want to check if the username or the email address are already in use. If they are I do not want to open a new account. When I call the constraint routine I can pass variables from within the DFV object, but can I pass something like a DBI database handle?
You can do that with an anonymous subroutine. I use the following conventions in my code:
my $users = My::Users->new;
...
constraints => {
email => [ {
name => 'format',
constraint => 'email'
}, {
name => 'exists',
constraint => sub {
!$users->search(email => lc $_[0]);
}
}
],
}So if search turns up a valid response, then the test fails.
Then I massage the data I get back from D::FV and in my templates I use something like the following to identify the problem (note that I use Template Toolkit instead of HTML::Template, but either will work):
[% IF invalid || missing %]
<div style="text-align: center; color: red">
There were problems processing your request:
</div>
<div style="text-align: center; color: red; font-size: 80%">
[% IF invalid.email.format %]The email address you provided does
not look valid<br />[% END %]
[% IF invalid.email.exists %]The email address you provided is
already registered<br />[% END %]
[% IF missing.email %]You have to provide an email address<br />[% END %]
</div>
[% END %]Cheers,
Cees
--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
