| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FillInForm; |
|
2
|
|
|
|
|
|
|
our $VERSION = '2.22'; |
|
3
|
27
|
|
|
27
|
|
370889
|
use integer; # no floating point math so far! |
|
|
27
|
|
|
|
|
593
|
|
|
|
27
|
|
|
|
|
138
|
|
|
4
|
27
|
|
|
27
|
|
847
|
use strict; # and no funny business, either. |
|
|
27
|
|
|
|
|
55
|
|
|
|
27
|
|
|
|
|
541
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
27
|
|
|
27
|
|
129
|
use Carp; # generate better errors with more context |
|
|
27
|
|
|
|
|
56
|
|
|
|
27
|
|
|
|
|
2716
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# required for UNIVERSAL->can |
|
10
|
|
|
|
|
|
|
require 5.005; |
|
11
|
|
|
|
|
|
|
|
|
12
|
27
|
|
|
27
|
|
173
|
use vars qw($VERSION @ISA); |
|
|
27
|
|
|
|
|
52
|
|
|
|
27
|
|
|
|
|
87658
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '2.21'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
|
17
|
58
|
|
|
58
|
1
|
25976
|
my $class = shift; |
|
18
|
58
|
|
|
|
|
152
|
my $self = bless {}, $class; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# required for attr_encoded |
|
21
|
|
|
|
|
|
|
|
|
22
|
58
|
|
33
|
|
|
321
|
my %arg = @_ || (); |
|
23
|
58
|
|
50
|
|
|
240
|
my $parser_class = $arg{parser_class} || 'HTML::Parser'; |
|
24
|
58
|
50
|
|
|
|
3561
|
eval "require $parser_class;" || die "require $parser_class failed: $@"; |
|
25
|
58
|
|
|
|
|
146641
|
@ISA = ($parser_class); |
|
26
|
|
|
|
|
|
|
|
|
27
|
58
|
|
|
|
|
605
|
$self->init(@_); |
|
28
|
|
|
|
|
|
|
|
|
29
|
58
|
50
|
|
|
|
3182
|
unless ($self->can('attr_encoded')) { |
|
30
|
0
|
|
|
|
|
0
|
die "attr_encoded method is missing. If are using HTML::Parser, you need at least version 3.26"; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# tell HTML::Parser not to decode attributes |
|
34
|
58
|
|
|
|
|
255
|
$self->attr_encoded(1); |
|
35
|
|
|
|
|
|
|
|
|
36
|
58
|
|
|
|
|
333
|
return $self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# a few shortcuts to fill() |
|
40
|
1
|
|
|
1
|
0
|
2
|
sub fill_file { my $self = shift; return $self->fill('file' ,@_); } |
|
|
1
|
|
|
|
|
3
|
|
|
41
|
1
|
|
|
1
|
0
|
2
|
sub fill_arrayref { my $self = shift; return $self->fill('arrayref' ,@_); } |
|
|
1
|
|
|
|
|
3
|
|
|
42
|
3
|
|
|
3
|
0
|
5
|
sub fill_scalarref { my $self = shift; return $self->fill('scalarref',@_); } |
|
|
3
|
|
|
|
|
8
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# track the keys we support. Useful for file-name detection. |
|
45
|
|
|
|
|
|
|
sub _known_keys { |
|
46
|
|
|
|
|
|
|
return { |
|
47
|
48
|
|
|
48
|
|
428
|
scalarref => 1, |
|
48
|
|
|
|
|
|
|
arrayref => 1, |
|
49
|
|
|
|
|
|
|
fdat => 1, |
|
50
|
|
|
|
|
|
|
fobject => 1, |
|
51
|
|
|
|
|
|
|
file => 1, |
|
52
|
|
|
|
|
|
|
target => 1, |
|
53
|
|
|
|
|
|
|
fill_password => 1, |
|
54
|
|
|
|
|
|
|
ignore_fields => 1, |
|
55
|
|
|
|
|
|
|
disable_fields => 1, |
|
56
|
|
|
|
|
|
|
invalid_fields => 1, |
|
57
|
|
|
|
|
|
|
invalid_class => 1, |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub fill { |
|
62
|
60
|
|
|
60
|
1
|
7476
|
my $self = shift; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# If we are called as a class method, go ahead and call new(). |
|
65
|
60
|
100
|
|
|
|
210
|
$self = $self->new if (not ref $self); |
|
66
|
|
|
|
|
|
|
|
|
67
|
60
|
|
|
|
|
108
|
my %option; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# If the first arg is a scalarref, translate that to scalarref => $first_arg |
|
70
|
60
|
100
|
|
|
|
392
|
if (ref $_[0] eq 'SCALAR') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
71
|
10
|
|
|
|
|
28
|
$option{scalarref} = shift; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'ARRAY') { |
|
74
|
1
|
|
|
|
|
6
|
$option{arrayref} = shift; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
elsif (ref $_[0] eq 'GLOB') { |
|
77
|
1
|
|
|
|
|
2
|
$option{file} = shift; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif (ref $_[0]) { |
|
80
|
0
|
|
|
|
|
0
|
croak "data source is not a reference type we understand"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
# Last chance, if the first arg isn't one of the known keys, we |
|
83
|
|
|
|
|
|
|
# assume it is a file name. |
|
84
|
|
|
|
|
|
|
elsif (not _known_keys()->{$_[0]} ) { |
|
85
|
1
|
|
|
|
|
3
|
$option{file} = shift; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
|
|
|
|
|
|
# Should be a known key. Nothing to do. |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Now, check to see if the next arg is also a reference. |
|
93
|
60
|
|
|
|
|
160
|
my $data; |
|
94
|
60
|
100
|
|
|
|
187
|
if (ref $_[0]) { |
|
95
|
9
|
|
|
|
|
17
|
$data = shift; |
|
96
|
9
|
50
|
|
|
|
38
|
$data = [$data] unless ref $data eq 'ARRAY'; |
|
97
|
|
|
|
|
|
|
|
|
98
|
9
|
|
|
|
|
27
|
for my $source (@$data) { |
|
99
|
9
|
100
|
|
|
|
82
|
if (ref $source eq 'HASH') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
7
|
|
|
|
|
14
|
push @{ $option{fdat} }, $source; |
|
|
7
|
|
|
|
|
23
|
|
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
elsif (ref $source) { |
|
103
|
2
|
50
|
|
|
|
15
|
if ($source->can('param')) { |
|
104
|
2
|
|
|
|
|
4
|
push @{ $option{fobject} }, $source; |
|
|
2
|
|
|
|
|
10
|
|
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
else { |
|
107
|
0
|
|
|
|
|
0
|
croak "data source $source does not supply a param method"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif (defined $source) { |
|
111
|
0
|
|
|
|
|
0
|
croak "data source $source is not a hash or object reference"; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# load in the rest of the options |
|
119
|
60
|
|
|
|
|
243
|
%option = (%option, @_); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# As suggested in the docs, merge multiple fdats into one. |
|
123
|
60
|
100
|
|
|
|
259
|
if (ref $option{fdat} eq 'ARRAY') { |
|
124
|
7
|
|
|
|
|
10
|
my %merged; |
|
125
|
7
|
|
|
|
|
12
|
for my $hash (@{ $option{fdat} }) { |
|
|
7
|
|
|
|
|
15
|
|
|
126
|
7
|
|
|
|
|
22
|
for my $key (keys %$hash) { |
|
127
|
29
|
|
|
|
|
56
|
$merged{$key} = $hash->{$key}; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
7
|
|
|
|
|
21
|
$option{'fdat'} = \%merged; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
60
|
|
|
|
|
104
|
my %ignore_fields; |
|
135
|
6
|
|
|
|
|
19
|
%ignore_fields = map { $_ => 1 } ( ref $option{'ignore_fields'} eq 'ARRAY' ) |
|
136
|
60
|
100
|
|
|
|
432
|
? @{ $option{ignore_fields} } : $option{ignore_fields} if exists( $option{ignore_fields} ); |
|
|
2
|
100
|
|
|
|
8
|
|
|
137
|
60
|
|
|
|
|
295
|
$self->{ignore_fields} = \%ignore_fields; |
|
138
|
|
|
|
|
|
|
|
|
139
|
60
|
|
|
|
|
108
|
my %disable_fields; |
|
140
|
2
|
|
|
|
|
9
|
%disable_fields = map { $_ => 1 } ( ref $option{'disable_fields'} eq 'ARRAY' ) |
|
141
|
60
|
100
|
|
|
|
144
|
? @{ $option{disable_fields} } : $option{disable_fields} if exists( $option{disable_fields} ); |
|
|
1
|
100
|
|
|
|
2
|
|
|
142
|
60
|
|
|
|
|
121
|
$self->{disable_fields} = \%disable_fields; |
|
143
|
|
|
|
|
|
|
|
|
144
|
60
|
|
|
|
|
86
|
my %invalid_fields; |
|
145
|
8
|
|
|
|
|
21
|
%invalid_fields = map { $_ => 1 } ( ref $option{'invalid_fields'} eq 'ARRAY' ) |
|
146
|
60
|
50
|
|
|
|
146
|
? @{ $option{invalid_fields} } : $option{invalid_fields} if exists( $option{invalid_fields} ); |
|
|
3
|
100
|
|
|
|
7
|
|
|
147
|
60
|
|
|
|
|
115
|
$self->{invalid_fields} = \%invalid_fields; |
|
148
|
|
|
|
|
|
|
|
|
149
|
60
|
100
|
|
|
|
164
|
if (my $fdat = $option{fdat}){ |
|
150
|
|
|
|
|
|
|
# Copy the structure to prevent side-effects. |
|
151
|
43
|
|
|
|
|
63
|
my %copy; |
|
152
|
43
|
|
|
|
|
86
|
keys %$fdat; # reset fdat if each or Dumper was called on fdat |
|
153
|
43
|
|
|
|
|
177
|
while(my($key, $val) = each %$fdat) { |
|
154
|
86
|
100
|
|
|
|
185
|
next if exists $ignore_fields{$key}; |
|
155
|
85
|
100
|
|
|
|
361
|
$copy{ $key } = ref $val eq 'ARRAY' ? [ @$val ] : $val; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
43
|
|
|
|
|
116
|
$self->{fdat} = \%copy; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# We want the reference to these objects to go out of scope at the |
|
161
|
|
|
|
|
|
|
# end of the method. |
|
162
|
60
|
|
|
|
|
223
|
local $self->{objects} = []; |
|
163
|
60
|
100
|
|
|
|
189
|
if(my $objects = $option{fobject}){ |
|
164
|
16
|
100
|
|
|
|
49
|
unless(ref($objects) eq 'ARRAY'){ |
|
165
|
13
|
|
|
|
|
29
|
$objects = [ $objects ]; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
16
|
|
|
|
|
40
|
for my $object (@$objects){ |
|
168
|
|
|
|
|
|
|
# make sure objects in 'param_object' parameter support param() |
|
169
|
17
|
100
|
|
|
|
301
|
defined($object->can('param')) or |
|
170
|
|
|
|
|
|
|
croak("HTML::FillInForm->fill called with fobject option, containing object of type " . ref($object) . " which lacks a param() method!"); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
15
|
|
|
|
|
34
|
$self->{objects} = $objects; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
59
|
100
|
|
|
|
147
|
if (my $target = $option{target}){ |
|
176
|
2
|
|
|
|
|
4
|
$self->{'target'} = $target; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
59
|
100
|
|
|
|
144
|
if (my $invalid_class = $option{invalid_class}){ |
|
180
|
1
|
|
|
|
|
3
|
$self->{'invalid_class'} = $invalid_class; |
|
181
|
|
|
|
|
|
|
} else { |
|
182
|
58
|
|
|
|
|
121
|
$self->{'invalid_class'} = 'invalid'; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
59
|
100
|
|
|
|
157
|
if (defined($option{fill_password})){ |
|
186
|
1
|
|
|
|
|
3
|
$self->{fill_password} = $option{fill_password}; |
|
187
|
|
|
|
|
|
|
} else { |
|
188
|
58
|
|
|
|
|
136
|
$self->{fill_password} = 1; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
59
|
|
|
|
|
133
|
$self->{clear_absent_checkboxes} = $option{clear_absent_checkboxes}; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# make sure method has data to fill in HTML form with! |
|
194
|
59
|
50
|
66
|
|
|
199
|
unless(exists $self->{fdat} || $self->{objects}){ |
|
195
|
0
|
|
|
|
|
0
|
croak("HTML::FillInForm->fillInForm() called without 'fobject' or 'fdat' parameter set"); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
59
|
|
|
|
|
163
|
local $self->{object_param_cache}; |
|
199
|
|
|
|
|
|
|
|
|
200
|
59
|
100
|
|
|
|
208
|
if(my $file = $option{file}){ |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
201
|
3
|
|
|
|
|
11
|
$self->parse_file($file); |
|
202
|
|
|
|
|
|
|
} elsif (my $scalarref = $option{scalarref}){ |
|
203
|
53
|
|
|
|
|
702
|
$self->parse($$scalarref); |
|
204
|
|
|
|
|
|
|
} elsif (my $arrayref = $option{arrayref}){ |
|
205
|
2
|
|
|
|
|
4
|
for (@$arrayref){ |
|
206
|
10
|
|
|
|
|
64
|
$self->parse($_); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
59
|
|
|
|
|
372
|
$self->eof; |
|
211
|
59
|
|
|
|
|
518
|
return delete $self->{output}; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# handles opening HTML tags such as |
|
215
|
|
|
|
|
|
|
sub start { |
|
216
|
307
|
|
|
307
|
1
|
1061
|
my ($self, $tagname, $attr, $attrseq, $origtext) = @_; |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# set the current form |
|
219
|
307
|
100
|
|
|
|
631
|
if ($tagname eq 'form') { |
|
220
|
25
|
|
|
|
|
50
|
$self->{object_param_cache} = {}; |
|
221
|
25
|
100
|
100
|
|
|
117
|
if (exists $attr->{'name'} || exists $attr->{'id'}) { |
|
222
|
6
|
|
66
|
|
|
20
|
$self->{'current_form'} = $attr->{'name'} || $attr->{'id'}; |
|
223
|
|
|
|
|
|
|
} else { |
|
224
|
|
|
|
|
|
|
# in case of previous one without |
|
225
|
19
|
|
|
|
|
37
|
delete $self->{'current_form'}; |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# This form is not my target. |
|
230
|
307
|
100
|
100
|
|
|
663
|
if (exists $self->{'target'} && |
|
|
|
|
100
|
|
|
|
|
|
231
|
|
|
|
|
|
|
(! exists $self->{'current_form'} || |
|
232
|
|
|
|
|
|
|
$self->{'current_form'} ne $self->{'target'})) { |
|
233
|
12
|
|
|
|
|
26
|
$self->{'output'} .= $origtext; |
|
234
|
12
|
|
|
|
|
57
|
return; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# HTML::Parser converts tagname to lowercase, so we don't need /i |
|
238
|
295
|
100
|
|
|
|
616
|
if ($self->{option_no_value}) { |
|
239
|
3
|
|
|
|
|
7
|
$self->{output} .= '>'; |
|
240
|
3
|
|
|
|
|
8
|
delete $self->{option_no_value}; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# Check if we need to disable this field |
|
244
|
|
|
|
|
|
|
$attr->{disabled} = 'disabled' |
|
245
|
|
|
|
|
|
|
if exists $attr->{'name'} and |
|
246
|
|
|
|
|
|
|
exists $self->{disable_fields}{ $attr->{'name'} } and |
|
247
|
|
|
|
|
|
|
$self->{disable_fields}{ $attr->{'name'} } and |
|
248
|
295
|
50
|
100
|
|
|
1026
|
not ( exists $attr->{disabled} and $attr->{disabled} ); |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# Check if we need to invalidate this field |
|
251
|
295
|
|
|
|
|
435
|
my $invalidating = 0; |
|
252
|
295
|
100
|
100
|
|
|
956
|
if (exists $attr->{name} and |
|
|
|
|
66
|
|
|
|
|
|
253
|
|
|
|
|
|
|
exists $self->{invalid_fields}{ $attr->{name} } and |
|
254
|
|
|
|
|
|
|
$self->{invalid_fields}{ $attr->{name} }) { |
|
255
|
8
|
|
|
|
|
13
|
$invalidating = 1; |
|
256
|
8
|
100
|
66
|
|
|
26
|
if (exists $attr->{class} and length $attr->{class}) { |
|
257
|
|
|
|
|
|
|
# don't add the class if it's already there |
|
258
|
3
|
100
|
|
|
|
41
|
unless ($attr->{class} =~ /\b\Q$self->{invalid_class}\E\b/) { |
|
259
|
2
|
|
|
|
|
7
|
$attr->{class} .= " $self->{invalid_class}"; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
} else { |
|
262
|
5
|
|
|
|
|
11
|
$attr->{class} = $self->{invalid_class}; |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
295
|
100
|
|
|
|
736
|
if ($tagname eq 'input'){ |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
267
|
136
|
100
|
|
|
|
396
|
my $value = exists $attr->{'name'} ? $self->_get_param($attr->{'name'}) : undef; |
|
268
|
|
|
|
|
|
|
# force hidden fields to have a value |
|
269
|
136
|
100
|
100
|
|
|
665
|
$value = '' if exists($attr->{'type'}) && $attr->{'type'} eq 'hidden' && ! exists $attr->{'value'} && ! defined $value; |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# browsers do not pass unchecked checkboxes at all, so hack around |
|
272
|
136
|
50
|
100
|
|
|
437
|
$value = '' if $self->{clear_absent_checkboxes} && !defined $value && exists($attr->{'type'}) && ($attr->{'type'} eq 'checkbox' || $attr->{'type'} eq 'radio'); |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
273
|
136
|
100
|
|
|
|
295
|
if (defined($value)){ |
|
274
|
|
|
|
|
|
|
# check for input type, noting that default type is text |
|
275
|
111
|
100
|
100
|
|
|
923
|
if (!exists $attr->{'type'} || |
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
$attr->{'type'} =~ /^(text|textfield|hidden|tel|search|url|email|datetime|date|month|week|time|datetime\-local|number|range|color|)$/i){ |
|
277
|
56
|
100
|
|
|
|
260
|
if ( ref($value) eq 'ARRAY' ) { |
|
278
|
7
|
|
|
|
|
17
|
$value = shift @$value; |
|
279
|
7
|
100
|
|
|
|
22
|
$value = '' unless defined $value; |
|
280
|
|
|
|
|
|
|
} |
|
281
|
56
|
|
|
|
|
134
|
$attr->{'value'} = __escapeHTML($value); |
|
282
|
|
|
|
|
|
|
} elsif (lc $attr->{'type'} eq 'password' && $self->{fill_password}) { |
|
283
|
3
|
100
|
|
|
|
11
|
if ( ref($value) eq 'ARRAY' ) { |
|
284
|
2
|
|
|
|
|
5
|
$value = shift @$value; |
|
285
|
2
|
100
|
|
|
|
8
|
$value = '' unless defined $value; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
3
|
|
|
|
|
8
|
$attr->{'value'} = __escapeHTML($value); |
|
288
|
|
|
|
|
|
|
} elsif (lc $attr->{'type'} eq 'radio'){ |
|
289
|
22
|
100
|
|
|
|
58
|
if ( ref($value) eq 'ARRAY' ) { |
|
290
|
4
|
|
|
|
|
8
|
$value = $value->[0]; |
|
291
|
4
|
100
|
|
|
|
9
|
$value = '' unless defined $value; |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
# value for radio boxes default to 'on', works with netscape |
|
294
|
22
|
100
|
|
|
|
52
|
$attr->{'value'} = 'on' unless exists $attr->{'value'}; |
|
295
|
22
|
100
|
|
|
|
49
|
if ($attr->{'value'} eq __escapeHTML($value)){ |
|
296
|
4
|
|
|
|
|
13
|
$attr->{'checked'} = 'checked'; |
|
297
|
|
|
|
|
|
|
} else { |
|
298
|
18
|
|
|
|
|
40
|
delete $attr->{'checked'}; |
|
299
|
|
|
|
|
|
|
} |
|
300
|
|
|
|
|
|
|
} elsif (lc $attr->{'type'} eq 'checkbox'){ |
|
301
|
|
|
|
|
|
|
# value for checkboxes default to 'on', works with netscape |
|
302
|
29
|
100
|
|
|
|
70
|
$attr->{'value'} = 'on' unless exists $attr->{'value'}; |
|
303
|
|
|
|
|
|
|
|
|
304
|
29
|
|
|
|
|
43
|
delete $attr->{'checked'}; # Everything is unchecked to start |
|
305
|
29
|
100
|
|
|
|
97
|
$value = [ $value ] unless ref($value) eq 'ARRAY'; |
|
306
|
29
|
|
|
|
|
59
|
foreach my $v ( @$value ) { |
|
307
|
35
|
100
|
|
|
|
68
|
if ( $attr->{'value'} eq __escapeHTML($v) ) { |
|
308
|
10
|
|
|
|
|
24
|
$attr->{'checked'} = 'checked'; |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
} |
|
311
|
|
|
|
|
|
|
# } else { |
|
312
|
|
|
|
|
|
|
# warn(qq(Input field of unknown type "$attr->{type}": $origtext)); |
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
} |
|
315
|
136
|
|
|
|
|
355
|
$self->{output} .= "<$tagname"; |
|
316
|
136
|
|
|
|
|
503
|
while (my ($key, $value) = each %$attr) { |
|
317
|
440
|
100
|
|
|
|
905
|
next if $key eq '/'; |
|
318
|
431
|
|
|
|
|
1693
|
$self->{output} .= sprintf qq( %s="%s"), $key, $value; |
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
# extra space put here to work around Opera 6.01/6.02 bug |
|
321
|
136
|
100
|
|
|
|
304
|
$self->{output} .= ' /' if $attr->{'/'}; |
|
322
|
136
|
|
|
|
|
927
|
$self->{output} .= ">"; |
|
323
|
|
|
|
|
|
|
} elsif ($tagname eq 'option'){ |
|
324
|
78
|
50
|
|
|
|
209
|
my $value = defined($self->{selectName}) ? $self->_get_param($self->{selectName}) : undef; |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# browsers do not pass selects with no selected options at all, |
|
327
|
|
|
|
|
|
|
# so hack around |
|
328
|
78
|
100
|
100
|
|
|
272
|
$value = '' if $self->{clear_absent_checkboxes} && !defined $value; |
|
329
|
|
|
|
|
|
|
|
|
330
|
78
|
100
|
|
|
|
216
|
$value = [ $value ] unless ( ref($value) eq 'ARRAY' ); |
|
331
|
|
|
|
|
|
|
|
|
332
|
78
|
100
|
|
|
|
164
|
if ( defined $value->[0] ){ |
|
333
|
54
|
100
|
|
|
|
107
|
delete $attr->{selected} if exists $attr->{selected}; |
|
334
|
|
|
|
|
|
|
|
|
335
|
54
|
100
|
|
|
|
105
|
if(defined($attr->{'value'})){ |
|
336
|
|
|
|
|
|
|
# option tag has value attr - |
|
337
|
|
|
|
|
|
|
|
|
338
|
30
|
100
|
|
|
|
52
|
if ($self->{selectMultiple}){ |
|
339
|
|
|
|
|
|
|
# check if the option tag belongs to a multiple option select |
|
340
|
27
|
|
|
|
|
50
|
foreach my $v ( grep { defined } @$value ) { |
|
|
36
|
|
|
|
|
101
|
|
|
341
|
36
|
100
|
|
|
|
77
|
if ( $attr->{'value'} eq __escapeHTML($v) ){ |
|
342
|
8
|
|
|
|
|
21
|
$attr->{selected} = 'selected'; |
|
343
|
|
|
|
|
|
|
} |
|
344
|
|
|
|
|
|
|
} |
|
345
|
|
|
|
|
|
|
} else { |
|
346
|
|
|
|
|
|
|
# if not every value of a fdat ARRAY belongs to a different select tag |
|
347
|
3
|
50
|
|
|
|
9
|
if (not $self->{selectSelected}){ |
|
348
|
3
|
100
|
|
|
|
8
|
if ( $attr->{'value'} eq __escapeHTML($value->[0])){ |
|
349
|
2
|
50
|
|
|
|
10
|
shift @$value if ref($value) eq 'ARRAY'; |
|
350
|
2
|
|
|
|
|
5
|
$attr->{selected} = 'selected'; |
|
351
|
2
|
|
|
|
|
4
|
$self->{selectSelected} = 1; # remember that an option tag is selected for this select tag |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
} else { |
|
356
|
|
|
|
|
|
|
# option tag has no value attr - |
|
357
|
|
|
|
|
|
|
# save for processing under text handler |
|
358
|
24
|
|
|
|
|
42
|
$self->{option_no_value} = __escapeHTML($value); |
|
359
|
|
|
|
|
|
|
} |
|
360
|
|
|
|
|
|
|
} |
|
361
|
78
|
|
|
|
|
164
|
$self->{output} .= "<$tagname"; |
|
362
|
78
|
|
|
|
|
256
|
while (my ($key, $value) = each %$attr) { |
|
363
|
61
|
|
|
|
|
280
|
$self->{output} .= sprintf qq( %s="%s"), $key, $value; |
|
364
|
|
|
|
|
|
|
} |
|
365
|
78
|
100
|
|
|
|
270
|
unless ($self->{option_no_value}){ |
|
366
|
|
|
|
|
|
|
# we can close option tag here |
|
367
|
54
|
|
|
|
|
319
|
$self->{output} .= ">"; |
|
368
|
|
|
|
|
|
|
} |
|
369
|
|
|
|
|
|
|
} elsif ($tagname eq 'textarea'){ |
|
370
|
|
|
|
|
|
|
# need to re-output the |
|
371
|
|
|
|
|
|
|
# (doesn't disable need this too?) |
|
372
|
11
|
100
|
|
|
|
50
|
if ($invalidating) { |
|
373
|
1
|
|
|
|
|
4
|
$self->{output} .= "<$tagname"; |
|
374
|
1
|
|
|
|
|
5
|
while (my ($key, $value) = each %$attr) { |
|
375
|
2
|
|
|
|
|
11
|
$self->{output} .= sprintf qq( %s="%s"), $key, $value; |
|
376
|
|
|
|
|
|
|
} |
|
377
|
1
|
|
|
|
|
2
|
$self->{output} .= ">"; |
|
378
|
|
|
|
|
|
|
} else { |
|
379
|
10
|
|
|
|
|
24
|
$self->{output} .= $origtext; |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
|
|
382
|
11
|
100
|
100
|
|
|
68
|
if ($attr->{'name'} and defined (my $value = $self->_get_param($attr->{'name'}))){ |
|
383
|
6
|
100
|
100
|
|
|
41
|
$value = (shift @$value || '') if ref($value) eq 'ARRAY'; |
|
384
|
|
|
|
|
|
|
# -> |
|
385
|
|
|
|
|
|
|
# we need to set outputText to 'no' so that 'foobar' won't be printed |
|
386
|
6
|
|
|
|
|
27
|
$self->{outputText} = 'no'; |
|
387
|
6
|
|
|
|
|
18
|
$self->{output} .= __escapeHTML($value); |
|
388
|
|
|
|
|
|
|
} |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
} elsif ($tagname eq 'select'){ |
|
391
|
29
|
|
|
|
|
115
|
$self->{selectName} = $attr->{'name'}; |
|
392
|
29
|
100
|
|
|
|
61
|
if (defined $attr->{'multiple'}){ |
|
393
|
20
|
|
|
|
|
35
|
$self->{selectMultiple} = 1; # helper var to remember if the select tag has the multiple attr set or not |
|
394
|
|
|
|
|
|
|
} else { |
|
395
|
9
|
|
|
|
|
19
|
$self->{selectMultiple} = 0; |
|
396
|
9
|
|
|
|
|
19
|
$self->{selectSelected} = 0; # helper var to remember if an option was already selected in the current select tag |
|
397
|
|
|
|
|
|
|
} |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
# need to re-output the |
|
400
|
|
|
|
|
|
|
# (doesn't disable need this too?) |
|
401
|
29
|
100
|
|
|
|
56
|
if ($invalidating) { |
|
402
|
1
|
|
|
|
|
4
|
$self->{output} .= "<$tagname"; |
|
403
|
1
|
|
|
|
|
6
|
while (my ($key, $value) = each %$attr) { |
|
404
|
2
|
|
|
|
|
9
|
$self->{output} .= sprintf qq( %s="%s"), $key, $value; |
|
405
|
|
|
|
|
|
|
} |
|
406
|
1
|
|
|
|
|
8
|
$self->{output} .= ">"; |
|
407
|
|
|
|
|
|
|
} else { |
|
408
|
28
|
|
|
|
|
177
|
$self->{output} .= $origtext; |
|
409
|
|
|
|
|
|
|
} |
|
410
|
|
|
|
|
|
|
} else { |
|
411
|
41
|
|
|
|
|
270
|
$self->{output} .= $origtext; |
|
412
|
|
|
|
|
|
|
} |
|
413
|
|
|
|
|
|
|
} |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub _get_param { |
|
416
|
222
|
|
|
222
|
|
437
|
my ($self, $param) = @_; |
|
417
|
|
|
|
|
|
|
|
|
418
|
222
|
100
|
|
|
|
464
|
return undef if $self->{ignore_fields}{$param}; |
|
419
|
|
|
|
|
|
|
|
|
420
|
216
|
100
|
|
|
|
647
|
return $self->{fdat}{$param} if exists $self->{fdat}{$param}; |
|
421
|
|
|
|
|
|
|
|
|
422
|
115
|
100
|
|
|
|
288
|
return $self->{object_param_cache}{$param} if exists $self->{object_param_cache}{$param}; |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
# traverse the list in reverse order for backwards compatibility |
|
425
|
|
|
|
|
|
|
# with the previous implementation. |
|
426
|
80
|
|
|
|
|
117
|
for my $o (reverse @{$self->{objects}}) { |
|
|
80
|
|
|
|
|
179
|
|
|
427
|
41
|
|
|
|
|
61
|
my @v; |
|
428
|
41
|
50
|
|
|
|
129
|
if ($o->can('multi_param')) { |
|
429
|
41
|
|
|
|
|
109
|
@v = $o->multi_param($param); |
|
430
|
|
|
|
|
|
|
} else { |
|
431
|
0
|
|
|
|
|
0
|
@v = $o->param($param); |
|
432
|
|
|
|
|
|
|
} |
|
433
|
|
|
|
|
|
|
|
|
434
|
41
|
100
|
|
|
|
1202
|
next unless @v; |
|
435
|
|
|
|
|
|
|
|
|
436
|
21
|
100
|
|
|
|
97
|
return $self->{object_param_cache}{$param} = @v > 1 ? \@v : $v[0]; |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
|
|
439
|
59
|
|
|
|
|
139
|
return undef; |
|
440
|
|
|
|
|
|
|
} |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# handles non-html text |
|
443
|
|
|
|
|
|
|
sub text { |
|
444
|
350
|
|
|
350
|
1
|
819
|
my ($self, $origtext) = @_; |
|
445
|
|
|
|
|
|
|
# just output text, unless replaced value of |
|
446
|
350
|
100
|
66
|
|
|
881
|
unless(exists $self->{outputText} && $self->{outputText} eq 'no'){ |
|
447
|
348
|
100
|
|
|
|
616
|
if(exists $self->{option_no_value}){ |
|
448
|
|
|
|
|
|
|
# dealing with option tag with no value - |
|
449
|
21
|
|
|
|
|
31
|
my $values = $self->{option_no_value}; |
|
450
|
21
|
|
|
|
|
30
|
my $value = $origtext; |
|
451
|
21
|
|
|
|
|
53
|
$value =~ s/^\s+//; |
|
452
|
21
|
|
|
|
|
41
|
$value =~ s/\s+$//; |
|
453
|
21
|
|
|
|
|
36
|
foreach my $v ( @$values ) { |
|
454
|
27
|
100
|
|
|
|
57
|
if ( $value eq $v ) { |
|
455
|
6
|
|
|
|
|
13
|
$self->{output} .= ' selected="selected"'; |
|
456
|
|
|
|
|
|
|
} |
|
457
|
|
|
|
|
|
|
} |
|
458
|
|
|
|
|
|
|
# close |
|
459
|
21
|
|
|
|
|
42
|
$self->{output} .= ">$origtext"; |
|
460
|
21
|
|
|
|
|
93
|
delete $self->{option_no_value}; |
|
461
|
|
|
|
|
|
|
} else { |
|
462
|
327
|
|
|
|
|
1773
|
$self->{output} .= $origtext; |
|
463
|
|
|
|
|
|
|
} |
|
464
|
|
|
|
|
|
|
} |
|
465
|
|
|
|
|
|
|
} |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
# handles closing HTML tags such as |
|
468
|
|
|
|
|
|
|
sub end { |
|
469
|
141
|
|
|
141
|
1
|
308
|
my ($self, $tagname, $origtext) = @_; |
|
470
|
141
|
50
|
|
|
|
287
|
if ($self->{option_no_value}) { |
|
471
|
0
|
|
|
|
|
0
|
$self->{output} .= '>'; |
|
472
|
0
|
|
|
|
|
0
|
delete $self->{option_no_value}; |
|
473
|
|
|
|
|
|
|
} |
|
474
|
141
|
100
|
|
|
|
370
|
if($tagname eq 'select'){ |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
475
|
29
|
|
|
|
|
54
|
delete $self->{selectName}; |
|
476
|
|
|
|
|
|
|
} elsif ($tagname eq 'textarea'){ |
|
477
|
11
|
|
|
|
|
21
|
delete $self->{outputText}; |
|
478
|
|
|
|
|
|
|
} elsif ($tagname eq 'form') { |
|
479
|
25
|
|
|
|
|
41
|
delete $self->{'current_form'}; |
|
480
|
|
|
|
|
|
|
} |
|
481
|
141
|
|
|
|
|
506
|
$self->{output} .= $origtext; |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub __escapeHTML { |
|
485
|
185
|
|
|
185
|
|
368
|
my ($toencode) = @_; |
|
486
|
|
|
|
|
|
|
|
|
487
|
185
|
50
|
|
|
|
413
|
return undef unless defined($toencode); |
|
488
|
185
|
|
|
|
|
351
|
$toencode =~ s/&/&/g; |
|
489
|
185
|
|
|
|
|
287
|
$toencode =~ s/\"/"/g; |
|
490
|
185
|
|
|
|
|
273
|
$toencode =~ s/>/>/g; |
|
491
|
185
|
|
|
|
|
265
|
$toencode =~ s/</g; |
|
492
|
185
|
|
|
|
|
531
|
return $toencode; |
|
493
|
|
|
|
|
|
|
} |
|
494
|
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
sub comment { |
|
496
|
4
|
|
|
4
|
1
|
28
|
my ( $self, $text ) = @_; |
|
497
|
|
|
|
|
|
|
# if it begins with '[if ' and doesn't end with '
|
|
498
|
|
|
|
|
|
|
# it's a "downlevel-revealed" conditional comment (stupid IE) |
|
499
|
|
|
|
|
|
|
# or |
|
500
|
|
|
|
|
|
|
# if it ends with '[endif]' then it's the end of a |
|
501
|
|
|
|
|
|
|
# "downlevel-revealed" conditional comment |
|
502
|
4
|
50
|
33
|
|
|
25
|
if( |
|
|
|
|
33
|
|
|
|
|
|
503
|
|
|
|
|
|
|
( |
|
504
|
|
|
|
|
|
|
( index($text, '[if ') == 0 ) |
|
505
|
|
|
|
|
|
|
&& |
|
506
|
|
|
|
|
|
|
( $text !~ /
|
|
507
|
|
|
|
|
|
|
) |
|
508
|
|
|
|
|
|
|
|| |
|
509
|
|
|
|
|
|
|
( $text eq '[endif]' ) |
|
510
|
|
|
|
|
|
|
) { |
|
511
|
0
|
|
|
|
|
0
|
$self->{output} .= ''; |
|
512
|
|
|
|
|
|
|
} else { |
|
513
|
4
|
|
|
|
|
12
|
$self->{output} .= ''; |
|
514
|
|
|
|
|
|
|
} |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
sub process { |
|
518
|
4
|
|
|
4
|
1
|
9
|
my ( $self, $token0, $text ) = @_; |
|
519
|
4
|
|
|
|
|
17
|
$self->{output} .= $text; |
|
520
|
|
|
|
|
|
|
} |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
sub declaration { |
|
523
|
2
|
|
|
2
|
1
|
21
|
my ( $self, $text ) = @_; |
|
524
|
2
|
|
|
|
|
23
|
$self->{output} .= ''; |
|
525
|
|
|
|
|
|
|
} |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
1; |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=pod |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
=encoding UTF-8 |
|
532
|
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
=head1 NAME |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
HTML::FillInForm - Populates HTML Forms with data. |
|
536
|
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=head1 VERSION |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
version 2.22 |
|
540
|
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
Fill HTML form with data. |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
$output = HTML::FillInForm->fill( \$html, $q ); |
|
546
|
|
|
|
|
|
|
$output = HTML::FillInForm->fill( \@html, [$q1,$q2] ); |
|
547
|
|
|
|
|
|
|
$output = HTML::FillInForm->fill( \*HTML, \%data ); |
|
548
|
|
|
|
|
|
|
$output = HTML::FillInForm->fill( 't.html', [\%data1,%data2] ); |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
The HTML can be provided as a scalarref, arrayref, filehandle or file. The data can come from one or more |
|
551
|
|
|
|
|
|
|
hashrefs, or objects which support a param() method, like CGI.pm, L, etc. |
|
552
|
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
This module fills in an HTML form with data from a Perl data structure, allowing you |
|
556
|
|
|
|
|
|
|
to keep the HTML and Perl separate. |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
Here are two common use cases: |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
1. A user submits an HTML form without filling out a required field. You want |
|
561
|
|
|
|
|
|
|
to redisplay the form with all the previous data in it, to make it easy for the |
|
562
|
|
|
|
|
|
|
user to see and correct the error. |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
2. You have just retrieved a record from a database and need to display it in |
|
565
|
|
|
|
|
|
|
an HTML form. |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=head1 fill |
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
The basic syntax is seen above the Synopsis. There are a few additional options. |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=head2 Options |
|
572
|
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
=head3 target => 'form1' |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
Suppose you have multiple forms in a html file and only want to fill in one. |
|
576
|
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
$output = HTML::FillInForm->fill(\$html, $q, target => 'form1'); |
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
This will fill in only the form inside |
|
580
|
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
=head3 fill_password => 0 |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
Passwords are filled in by default. To disable: |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
fill_password => 0 |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=head3 ignore_fields => [] |
|
590
|
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
To disable the filling of some fields: |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
ignore_fields => ['prev','next'] |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
=head3 disable_fields => [] |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
To disable fields from being edited: |
|
598
|
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
disable_fields => [ 'uid', 'gid' ] |
|
600
|
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=head3 invalid_fields => [] |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
To mark fields as being invalid (CSS class set to "invalid" or |
|
604
|
|
|
|
|
|
|
whatever you set invalid_class to): |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
invalid_fields => [ 'uid', 'gid' ] |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=head3 invalid_class => "invalid" |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
The CSS class which will be used to mark fields invalid. Defaults to |
|
611
|
|
|
|
|
|
|
"invalid". |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
=head3 clear_absent_checkboxes => 0 |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
Absent fields are not cleared or in any way changed. This is |
|
616
|
|
|
|
|
|
|
not what you want when you deal with checkboxes which are not sent |
|
617
|
|
|
|
|
|
|
by browser at all when cleared by user. |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
To remove "checked" attribute from checkboxes and radio buttons and |
|
620
|
|
|
|
|
|
|
attribute "selected" from options of select lists for which there's no |
|
621
|
|
|
|
|
|
|
data: |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
clear_absent_checkboxes => 1 |
|
624
|
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=head2 File Upload fields |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
File upload fields cannot be supported directly. Workarounds include asking the |
|
628
|
|
|
|
|
|
|
user to re-attach any file uploads or fancy server-side storage and |
|
629
|
|
|
|
|
|
|
referencing. You are on your own. |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
=head2 Clearing Fields |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
Fields are cleared if you set their value to an empty string or empty arrayref but not undef: |
|
634
|
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
# this will leave the form element foo untouched |
|
636
|
|
|
|
|
|
|
HTML::FillInForm->fill(\$html, { foo => undef }); |
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
# this will set clear the form element foo |
|
639
|
|
|
|
|
|
|
HTML::FillInForm->fill(\$html, { foo => "" }); |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
It has been suggested to add a option to change the behavior so that undef |
|
642
|
|
|
|
|
|
|
values will clear the form elements. Patches welcome. |
|
643
|
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
You can also use C option to clear |
|
645
|
|
|
|
|
|
|
checkboxes, radio buttons and selects without corresponding keys in |
|
646
|
|
|
|
|
|
|
the data: |
|
647
|
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
# this will set clear the form element foo (and all others except |
|
649
|
|
|
|
|
|
|
# bar) |
|
650
|
|
|
|
|
|
|
HTML::FillInForm->fill(\$html, { bar => 123 }, |
|
651
|
|
|
|
|
|
|
clear_absent_checkboxes => 1); |
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=head1 Old syntax |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
You probably need to read no further. The remaining docs concern the |
|
656
|
|
|
|
|
|
|
1.x era syntax, which is still supported. |
|
657
|
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=head2 new |
|
659
|
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Call C to create a new FillInForm object: |
|
661
|
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
$fif = HTML::FillInForm->new; |
|
663
|
|
|
|
|
|
|
$fif->fill(...); |
|
664
|
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
In theory, there is a slight performance benefit to calling C before C if you make multiple |
|
666
|
|
|
|
|
|
|
calls to C before you destroy the object. Benchmark before optimizing. |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
=head2 fill ( old syntax ) |
|
669
|
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
Instead of having your HTML and data types auto-detected, you can declare them explicitly in your |
|
671
|
|
|
|
|
|
|
call to C: |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
HTML source options: |
|
674
|
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
arrayref => @html |
|
676
|
|
|
|
|
|
|
scalarref => $html |
|
677
|
|
|
|
|
|
|
file => \*HTML |
|
678
|
|
|
|
|
|
|
file => 't.html' |
|
679
|
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
Fill Data options: |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
fobject => $data_obj # with param() method |
|
683
|
|
|
|
|
|
|
fdat => \%data |
|
684
|
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
Additional methods are also available: |
|
686
|
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
fill_file(\*HTML,...); |
|
688
|
|
|
|
|
|
|
fill_file('t.html',...); |
|
689
|
|
|
|
|
|
|
fill_arrayref(\@html,...); |
|
690
|
|
|
|
|
|
|
fill_scalarref(\$html,...); |
|
691
|
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=head1 USING AN ALTERNATE PARSER |
|
693
|
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
It's possible to use an alternate parser to L if the alternate |
|
695
|
|
|
|
|
|
|
provides a sufficiently compatible interface. For example, when a Pure Perl |
|
696
|
|
|
|
|
|
|
implementation of HTML::Parser appears, it could be used for portability. The syntax |
|
697
|
|
|
|
|
|
|
is simply to provide a C to new(); |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
HTML::FillInForm->new( parser_class => 'MyAlternate::Parser' ); |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=head1 CALLING FROM OTHER MODULES |
|
702
|
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
=head2 Apache::PageKit |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
To use HTML::FillInForm in L is easy. It is |
|
706
|
|
|
|
|
|
|
automatically called for any page that includes a |
|
707
|
|
|
|
|
|
|
It can be turned on or off by using the C configuration |
|
708
|
|
|
|
|
|
|
option. |
|
709
|
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=head2 Apache::ASP v2.09 and above |
|
711
|
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
HTML::FillInForm is now integrated with Apache::ASP. To activate, use |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
PerlSetVar FormFill 1 |
|
715
|
|
|
|
|
|
|
$Response->{FormFill} = 1 |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
=head2 HTML::Mason |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
Using HTML::FillInForm from HTML::Mason is covered in the FAQ on |
|
720
|
|
|
|
|
|
|
the masonhq.com website at |
|
721
|
|
|
|
|
|
|
L |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
=head1 SECURITY |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
Note that you might want to think about caching issues if you have password |
|
726
|
|
|
|
|
|
|
fields on your page. There is a discussion of this issue at |
|
727
|
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
http://www.perlmonks.org/index.pl?node_id=70482 |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
In summary, some browsers will cache the output of CGI scripts, and you |
|
731
|
|
|
|
|
|
|
can control this by setting the Expires header. For example, use |
|
732
|
|
|
|
|
|
|
C<-expires> in L or set C to I in |
|
733
|
|
|
|
|
|
|
Config.xml file of L. |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
=head1 TRANSLATION |
|
736
|
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
Kato Atsushi has translated these docs into Japanese, available from |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
http://perldoc.jp |
|
740
|
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
=head1 BUGS |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
Please submit any bug reports to tjmather@maxmind.com. |
|
744
|
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
=head1 NOTES |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
Requires Perl 5.005 and L version 3.26. |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
I wrote this module because I wanted to be able to insert CGI data |
|
750
|
|
|
|
|
|
|
into HTML forms, |
|
751
|
|
|
|
|
|
|
but without combining the HTML and Perl code. CGI.pm and Embperl allow you so |
|
752
|
|
|
|
|
|
|
insert CGI data into forms, but require that you mix HTML with Perl. |
|
753
|
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
There is a nice review of the module available here: |
|
755
|
|
|
|
|
|
|
L |
|
756
|
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
758
|
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
L, |
|
760
|
|
|
|
|
|
|
L, |
|
761
|
|
|
|
|
|
|
L, |
|
762
|
|
|
|
|
|
|
L |
|
763
|
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
=head1 CREDITS |
|
765
|
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
Fixes, Bug Reports, Docs have been generously provided by: |
|
767
|
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
Alex Kapranoff Miika Pekkarinen |
|
769
|
|
|
|
|
|
|
Michael Fisher Sam Tregar |
|
770
|
|
|
|
|
|
|
Tatsuhiko Miyagawa Joseph Yanni |
|
771
|
|
|
|
|
|
|
Boris Zentner Philip Mak |
|
772
|
|
|
|
|
|
|
Dave Rolsky Jost Krieger |
|
773
|
|
|
|
|
|
|
Patrick Michael Kane Gabriel Burka |
|
774
|
|
|
|
|
|
|
Ade Olonoh Bill Moseley |
|
775
|
|
|
|
|
|
|
Tom Lancaster James Tolley |
|
776
|
|
|
|
|
|
|
Martin H Sluka Dan Kubb |
|
777
|
|
|
|
|
|
|
Mark Stosberg Alexander Hartmaier |
|
778
|
|
|
|
|
|
|
Jonathan Swartz Paul Miller |
|
779
|
|
|
|
|
|
|
Trevor Schellhorn Anthony Ettinger |
|
780
|
|
|
|
|
|
|
Jim Miner Simon P. Ditner |
|
781
|
|
|
|
|
|
|
Paul Lindner Michael Peters |
|
782
|
|
|
|
|
|
|
Maurice Aubrey Trevor Schellhorn |
|
783
|
|
|
|
|
|
|
Andrew Creer |
|
784
|
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
Thanks! |
|
786
|
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
=head1 AUTHOR |
|
788
|
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
TJ Mather, tjmather@maxmind.com |
|
790
|
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
792
|
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
This software is copyright (c) 2000 by TJ Mather, tjmather@maxmind.com. |
|
794
|
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
796
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
797
|
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
=cut |
|
799
|
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
__END__ |