| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FormHandlerX::Form::Contact; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
45711
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
57
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
486
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
HTML::FormHandlerX::Form::Contact - An HTML::FormHandler contact form. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.04 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
You know, that contact form you create day-in, day-out. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
From a usability perspective in form design, it is advised to only ask for the minimal information you actually need, don't bombard a user with several fields if all you really need is one. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use HTML::FormHandlerX::Form::Contact; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $form = HTML::FormHandlerX::Form::Contact->new( active => [ qw( name email subject message ) ] ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$form->process( params => { name => $name, |
|
33
|
|
|
|
|
|
|
email => $email, |
|
34
|
|
|
|
|
|
|
subject => $subject, |
|
35
|
|
|
|
|
|
|
message => $message, |
|
36
|
|
|
|
|
|
|
} ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ( $form->validated ) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
|
|
|
|
|
|
# do something... |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
674
|
use HTML::FormHandler::Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 Fields |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
All fields will be rendered with a wrapper div with an id of C<< field-<field-name> >>. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
If a field is activated, it will be a required field. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This supports the idea of keeping your forms as simple as possible, if you don't need it, don't ask for it. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 name |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$form->field('name'); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has_field name => ( type => 'Text', |
|
66
|
|
|
|
|
|
|
required => 1, |
|
67
|
|
|
|
|
|
|
messages => { required => 'Your name is required.' }, |
|
68
|
|
|
|
|
|
|
tags => { no_errors => 1 }, |
|
69
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-name' }, |
|
70
|
|
|
|
|
|
|
inactive => 1, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 email |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$form->field('email'); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Validation performed as-per L<Email::Valid>. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has_field email => ( type => 'Email', |
|
82
|
|
|
|
|
|
|
required => 1, |
|
83
|
|
|
|
|
|
|
messages => { required => 'Your email is required.' }, |
|
84
|
|
|
|
|
|
|
tags => { no_errors => 1 }, |
|
85
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-email' }, |
|
86
|
|
|
|
|
|
|
inactive => 1, |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head3 telephone |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$form->field('telephone'); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Validation ensures there's a number in this field, but nothing more complicated. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has_field telephone => ( type => 'Text', |
|
98
|
|
|
|
|
|
|
required => 1, |
|
99
|
|
|
|
|
|
|
messages => { required => 'Your telephone number is required.' }, |
|
100
|
|
|
|
|
|
|
tags => { no_errors => 1 }, |
|
101
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-telephone' }, |
|
102
|
|
|
|
|
|
|
inactive => 1, |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub validate_telephone |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
|
|
|
|
|
|
my ( $self, $field ) = @_; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if ( $field->value !~ /\d/ ) |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
|
|
|
|
|
|
$field->add_error( "Your telephone number doesn't contain any digits." ); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head3 subject |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$form->field('subject'); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
has_field subject => ( type => 'Text', |
|
122
|
|
|
|
|
|
|
required => 1, |
|
123
|
|
|
|
|
|
|
messages => { required => 'The subject is required.' }, |
|
124
|
|
|
|
|
|
|
tags => { no_errors => 1 }, |
|
125
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-subject' }, |
|
126
|
|
|
|
|
|
|
inactive => 1, |
|
127
|
|
|
|
|
|
|
); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head3 message |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$form->field('message'); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
has_field message => ( type => 'TextArea', |
|
136
|
|
|
|
|
|
|
required => 1, |
|
137
|
|
|
|
|
|
|
messages => { required => 'The message is required.' }, |
|
138
|
|
|
|
|
|
|
tags => { no_errors => 1 }, |
|
139
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-message' }, |
|
140
|
|
|
|
|
|
|
inactive => 1, |
|
141
|
|
|
|
|
|
|
); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head3 submit |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$form->field('submit'); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
The value of the submit button will be 'Send Message' by default. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
has_field submit => ( type => 'Submit', |
|
152
|
|
|
|
|
|
|
value => 'Send Message', |
|
153
|
|
|
|
|
|
|
wrapper_attr => { id => 'field-submit', }, |
|
154
|
|
|
|
|
|
|
); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 Instance Methods |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head3 html_attributes |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This method has been populated to ensure all fields in error have the C<error> CSS class assigned to the labels. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See L<HTML::FormHandler> for more details. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub html_attributes |
|
167
|
|
|
|
|
|
|
{ |
|
168
|
|
|
|
|
|
|
my ($self, $field, $type, $attr, $result) = @_; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
if( $type eq 'label' && $result->has_errors ) |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
|
|
|
|
|
|
push @{$attr->{class}}, 'error'; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 AUTHOR |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Rob Brown, C<< <rob at intelcompute.com> >> |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 BUGS |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-html-formhandlerx-form-contact at rt.cpan.org>, or through |
|
183
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-FormHandlerX-Form-Contact>. I will be notified, and then you'll |
|
184
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 SUPPORT |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
perldoc HTML::FormHandlerX::Form::Contact |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
You can also look for information at: |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=over 4 |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-FormHandlerX-Form-Contact> |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L<http://annocpan.org/dist/HTML-FormHandlerX-Form-Contact> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/HTML-FormHandlerX-Form-Contact> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * Search CPAN |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/HTML-FormHandlerX-Form-Contact/> |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Copyright 2012 Rob Brown. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
221
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
222
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; # End of HTML::FormHandlerX::Form::Contact |
|
229
|
|
|
|
|
|
|
|