At 08:51 PM 12/5/2003 -0500, you wrote:
>John Day wrote:
>>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 %]
OK, I get that much. Two constraints one for apparent validity and one for existence.
The next thing I have to grapple with is My::Users! I have over ten years of Perl, but only recently started using OO features and I have never written an OO module. So a couple of questions:
1.. What is the ! in front of the method name?
2.. How would the method get the database handle which has been created in the setup sub in CGI::A?
3.. Would you happen to have some example code for such a module so I can see how it works?
This is all very different to writing largely procedural code which is basically what I have done before.
John
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.