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