1HTML::FormFu::ValidatorU(s3e)r Contributed Perl DocumentaHtTiMoLn::FormFu::Validator(3)
2
3
4
6 HTML::FormFu::Validator - Validator Base Class
7
13 Try to avoid using callbacks if possible. Below is a more maintainable
14 and reusable approach, which also keeps the code out of the controller.
15
16 A normal application's directory would contain:
17
18 lib/HTML/FormFu/Constraint/MyApp/
19 lib/HTML/FormFu/Validator/MyApp/
20 lib/HTML/FormFu/Plugin/MyApp/
21 etc.
22
23 Then, the form config file would just need:
24
25 validator: 'MyApp::SomeValidator'
26
27 And the class would be something like this:
28
29 package HTML::FormFu::Validator::MyApp::SomeValidator;
30 use strict;
31 use warnings;
32 use base 'HTML::FormFu::Validator';
33
34 sub validate_value {
35 my ( $self, $value, $params ) = @_;
36
37 my $c = $self->form->stash->{context};
38
39 return 1 if $c->model('DBIC')->is_valid($value);
40
41 # assuming you want to return a custom error message
42 # which perhaps includes something retrieved from the model
43 # otherwise, just return 0
44 die HTML::FormFu::Exception::Validator->new({
45 message => 'custom error message',
46 });
47 }
48
49 1;
50
51 HTML::FormFu::Validator::Callback
52
54 Carl Franks, "cfranks@cpan.org"
55
57 This library is free software, you can redistribute it and/or modify it
58 under the same terms as Perl itself.
59
60
61
62perl v5.12.1 2010-05-23 HTML::FormFu::Validator(3)