line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::FillInForm::ForceUTF8; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23497
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
2220
|
use NEXT; |
|
1
|
|
|
|
|
5011
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
797
|
use HTML::FillInForm::ForceUTF8; |
|
1
|
|
|
|
|
19939
|
|
|
1
|
|
|
|
|
290
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Catalyst::Plugin::FillInForm::ForceUTF8 - FillInForm with utf8 flag for Catalyst |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Catalyst 'FillInForm::ForceUTF8'; |
16
|
|
|
|
|
|
|
# that's it, if Catalyst::Plugin::FormValidator is being used |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# OR, manually: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# in MyApp.pm; assume $c->stash->data is seeded elsewhere |
21
|
|
|
|
|
|
|
sub end : Private { |
22
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
23
|
|
|
|
|
|
|
$c->forward('MyApp::V::TT') unless $c->res->output; |
24
|
|
|
|
|
|
|
$c->fillform( $c->stash->data ); |
25
|
|
|
|
|
|
|
# .... |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# you can abort automatic fillform with configuration. |
28
|
|
|
|
|
|
|
# (default: 1, same as Catalyst::Plugin::FillInForm behavior) |
29
|
|
|
|
|
|
|
MyApp->config->( |
30
|
|
|
|
|
|
|
fillinform->{ |
31
|
|
|
|
|
|
|
auto => 0 |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Fill forms automatically, based on data from a previous HTML |
38
|
|
|
|
|
|
|
form. Typically (but not necessarily) used in conjunction with |
39
|
|
|
|
|
|
|
L<Catalyst::Plugin::FormValidator>. This module automatically |
40
|
|
|
|
|
|
|
inserts data from a previous HTML form into HTML input fields, |
41
|
|
|
|
|
|
|
textarea fields, radio buttons, checkboxes, and select |
42
|
|
|
|
|
|
|
tags. It is an instance of L<HTML::FillInForm>, which itself |
43
|
|
|
|
|
|
|
is a subclass of L<HTML::Parser>, which it uses to parse the |
44
|
|
|
|
|
|
|
HTML and insert the values into the proper form tags. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The usual application is after a user submits an HTML form |
47
|
|
|
|
|
|
|
without filling out a required field, or with errors in fields |
48
|
|
|
|
|
|
|
having specified constraints. FillInForm is used to |
49
|
|
|
|
|
|
|
redisplay the HTML form with all the form elements containing |
50
|
|
|
|
|
|
|
the submitted info. FillInForm can also be used to fill forms |
51
|
|
|
|
|
|
|
with data from any source, e.g. directly from your database. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 EXTENDED METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head3 finalize |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Will automatically fill in forms, based on the parameters in |
58
|
|
|
|
|
|
|
C<$c-E<gt>req-E<gt>parameters>, if the last form has missing |
59
|
|
|
|
|
|
|
or invalid fields, and if C<Catalyst::Plugin::FormValidator> |
60
|
|
|
|
|
|
|
is being used. C<finalize> is called automatically by the |
61
|
|
|
|
|
|
|
Catalyst Engine; the end user will not have to call it |
62
|
|
|
|
|
|
|
directly. (In fact, it should never be called directly by the |
63
|
|
|
|
|
|
|
end user.) If you want to avoid this behavior, add auto => 0 |
64
|
|
|
|
|
|
|
to config. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub finalize { |
69
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $config = $c->config->{fillinform}; |
72
|
0
|
0
|
|
|
|
|
my $auto = exists $config->{auto} ? $config->{auto} : 1; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
0
|
|
|
|
if ( $auto && $c->isa('Catalyst::Plugin::FormValidator') ) { |
75
|
0
|
0
|
0
|
|
|
|
$c->fillform |
|
|
|
0
|
|
|
|
|
76
|
|
|
|
|
|
|
if $c->form->has_missing |
77
|
|
|
|
|
|
|
|| $c->form->has_invalid |
78
|
|
|
|
|
|
|
|| $c->stash->{error}; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
return $c->NEXT::finalize(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 fillform |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Fill a form, based on request parameters (the default) or any |
88
|
|
|
|
|
|
|
other specified data hash. You would call this manually if |
89
|
|
|
|
|
|
|
you're getting your data from some source other than the |
90
|
|
|
|
|
|
|
parameters (e.g. if you're seeding an edit form with the |
91
|
|
|
|
|
|
|
results of a database query), or if you're using some other |
92
|
|
|
|
|
|
|
validation system than C<Catalyst::Plugin::FormValidator>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$c->fillform; # defaults to $c->req->parameters |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# OR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$c->fillform( \%data_hash ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
C<fillform> must be called after an HTML template has been |
101
|
|
|
|
|
|
|
rendered. A typical way of using it is to place it immediately |
102
|
|
|
|
|
|
|
after your C<forward> call to your view class, which might be |
103
|
|
|
|
|
|
|
in a built-in C<end> action in your application class. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub render : ActionClass('RenderView') {} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub end : Private { |
108
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
109
|
|
|
|
|
|
|
$c->forward('render'); |
110
|
|
|
|
|
|
|
$c->fillform; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub fillform { |
116
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
117
|
0
|
|
0
|
|
|
|
my $fdat = shift || $c->request->parameters; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$c->response->output( |
120
|
|
|
|
|
|
|
HTML::FillInForm::ForceUTF8->new->fill( |
121
|
|
|
|
|
|
|
scalarref => \$c->response->{body}, |
122
|
|
|
|
|
|
|
fdat => $fdat |
123
|
|
|
|
|
|
|
) |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 CONFIGURATION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head3 auto |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can abort automatic fillform with configuration, even if |
132
|
|
|
|
|
|
|
C<Catalyst::Plugin::FormValidator> is loaded. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
MyApp->config->( |
135
|
|
|
|
|
|
|
fillinform->{ |
136
|
|
|
|
|
|
|
auto => 0 |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Plugin::FormValidator>, L<HTML::FillInForm::ForceUTF8>, L<Catalyst::Plugin::FillInForm>,. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Sebastian Riedel, C<sri@cpan.org> |
147
|
|
|
|
|
|
|
Marcus Ramberg, C<mramberg@cpan.org> |
148
|
|
|
|
|
|
|
Jesse Sheidlower, C<jester@panix.com> |
149
|
|
|
|
|
|
|
Hideo Kimura, C<hide@hide-k.net> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
154
|
|
|
|
|
|
|
the same terms as Perl itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |