line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
HTML::FormTemplate - Make data-defined persistant forms, reports |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
###################################################################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package HTML::FormTemplate; |
10
|
|
|
|
|
|
|
require 5.004; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module |
13
|
|
|
|
|
|
|
# is free software; you can redistribute it and/or modify it under the same terms |
14
|
|
|
|
|
|
|
# as Perl itself. However, I do request that this copyright information and |
15
|
|
|
|
|
|
|
# credits remain attached to the file. If you modify this module and |
16
|
|
|
|
|
|
|
# redistribute a changed version then please attach a note listing the |
17
|
|
|
|
|
|
|
# modifications. This module is available "as-is" and the author can not be held |
18
|
|
|
|
|
|
|
# accountable for any problems resulting from its use. |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
1722
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
21
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
22
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
76
|
|
23
|
|
|
|
|
|
|
$VERSION = '2.03'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Perl Version |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
5.004 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 Standard Modules |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
I |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Nonstandard Modules |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Class::ParamParser 1.041 |
40
|
|
|
|
|
|
|
HTML::EasyTags 1.071 |
41
|
|
|
|
|
|
|
Data::MultiValuedHash 1.081 |
42
|
|
|
|
|
|
|
CGI::MultiValuedHash 1.09 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
###################################################################### |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
854
|
use Class::ParamParser 1.041; |
|
1
|
|
|
|
|
1007
|
|
|
1
|
|
|
|
|
36
|
|
49
|
|
|
|
|
|
|
@ISA = qw( Class::ParamParser ); |
50
|
1
|
|
|
1
|
|
983
|
use HTML::EasyTags 1.071; |
|
1
|
|
|
|
|
2495
|
|
|
1
|
|
|
|
|
39
|
|
51
|
1
|
|
|
1
|
|
1180
|
use Data::MultiValuedHash 1.081; |
|
1
|
|
|
|
|
3378
|
|
|
1
|
|
|
|
|
30
|
|
52
|
1
|
|
|
1
|
|
966
|
use CGI::MultiValuedHash 1.09; |
|
1
|
|
|
|
|
2711
|
|
|
1
|
|
|
|
|
24022
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
###################################################################### |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#!/usr/bin/perl |
59
|
|
|
|
|
|
|
use strict; |
60
|
|
|
|
|
|
|
use warnings; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use HTML::FormTemplate; |
63
|
|
|
|
|
|
|
use HTML::EasyTags; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my @definitions = ( |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
visible_title => "What's your name?", |
68
|
|
|
|
|
|
|
type => 'textfield', |
69
|
|
|
|
|
|
|
name => 'name', |
70
|
|
|
|
|
|
|
is_required => 1, |
71
|
|
|
|
|
|
|
}, { |
72
|
|
|
|
|
|
|
visible_title => "What's the combination?", |
73
|
|
|
|
|
|
|
type => 'checkbox_group', |
74
|
|
|
|
|
|
|
name => 'words', |
75
|
|
|
|
|
|
|
'values' => ['eenie', 'meenie', 'minie', 'moe'], |
76
|
|
|
|
|
|
|
default => ['eenie', 'minie'], |
77
|
|
|
|
|
|
|
}, { |
78
|
|
|
|
|
|
|
visible_title => "What's your favorite colour?", |
79
|
|
|
|
|
|
|
type => 'popup_menu', |
80
|
|
|
|
|
|
|
name => 'color', |
81
|
|
|
|
|
|
|
'values' => ['red', 'green', 'blue', 'chartreuse'], |
82
|
|
|
|
|
|
|
}, { |
83
|
|
|
|
|
|
|
type => 'submit', |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $query_string = ''; |
88
|
|
|
|
|
|
|
read( STDIN, $query_string, $ENV{'CONTENT_LENGTH'} ); |
89
|
|
|
|
|
|
|
chomp( $query_string ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $form = HTML::FormTemplate->new(); |
92
|
|
|
|
|
|
|
$form->form_submit_url( |
93
|
|
|
|
|
|
|
'http://'.($ENV{'HTTP_HOST'} || '127.0.0.1').$ENV{'SCRIPT_NAME'} ); |
94
|
|
|
|
|
|
|
$form->field_definitions( \@definitions ); |
95
|
|
|
|
|
|
|
$form->user_input( $query_string ); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my ($mail_worked, $mail_failed); |
98
|
|
|
|
|
|
|
unless( $form->new_form() ) { |
99
|
|
|
|
|
|
|
if( open( MAIL, "|/usr/lib/sendmail -t") ) { |
100
|
|
|
|
|
|
|
print MAIL "To: perl\@DarrenDuncan.net\n"; |
101
|
|
|
|
|
|
|
print MAIL "From: perl\@DarrenDuncan.net\n"; |
102
|
|
|
|
|
|
|
print MAIL "Subject: A Simple Example HTML::FormTemplate Submission\n"; |
103
|
|
|
|
|
|
|
print MAIL "\n"; |
104
|
|
|
|
|
|
|
print MAIL $form->make_text_input_echo()."\n"; |
105
|
|
|
|
|
|
|
close ( MAIL ); |
106
|
|
|
|
|
|
|
$mail_worked = 1; |
107
|
|
|
|
|
|
|
} else { |
108
|
|
|
|
|
|
|
$mail_failed = 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $tagmaker = HTML::EasyTags->new(); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
print |
115
|
|
|
|
|
|
|
"Status: 200 OK\n", |
116
|
|
|
|
|
|
|
"Content-type: text/html\n\n", |
117
|
|
|
|
|
|
|
$tagmaker->start_html( 'A Simple Example' ), |
118
|
|
|
|
|
|
|
$tagmaker->h1( 'A Simple Example' ), |
119
|
|
|
|
|
|
|
$form->make_html_input_form( 1 ), |
120
|
|
|
|
|
|
|
$tagmaker->hr, |
121
|
|
|
|
|
|
|
$form->new_form() ? '' : $form->make_html_input_echo( 1 ), |
122
|
|
|
|
|
|
|
$mail_worked ? " Your favorites were emailed. \n" : '', |
123
|
|
|
|
|
|
|
$mail_failed ? " Error emailing your favorites. \n" : '', |
124
|
|
|
|
|
|
|
$tagmaker->end_html; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This Perl 5 object class can create web fill-out forms as well as parse, |
129
|
|
|
|
|
|
|
error-check, and report their contents. Forms can start out blank or with |
130
|
|
|
|
|
|
|
initial values, or by repeating the user's last input values. Facilities for |
131
|
|
|
|
|
|
|
interactive user-input-correction are also provided. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The class is designed so that a form can be completely defined, using |
134
|
|
|
|
|
|
|
field_definitions(), before any html is generated or any error-checking is done. |
135
|
|
|
|
|
|
|
For that reason, a form can be generated multiple times, each with a single |
136
|
|
|
|
|
|
|
function call, while the form only has to be defined once. Form descriptions can |
137
|
|
|
|
|
|
|
optionally be read from a file by the calling code, making that code a lot more |
138
|
|
|
|
|
|
|
generic and robust than code which had to define the field manually. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 OVERVIEW |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
If the calling code provides a MultiValuedHash object or HASH ref containing the |
143
|
|
|
|
|
|
|
parsed user input from the last time the form was submitted, via user_input(), |
144
|
|
|
|
|
|
|
then the newly generated form will incorporate that, making the entered values |
145
|
|
|
|
|
|
|
persistant. Since the calling code has control over the provided "user input", |
146
|
|
|
|
|
|
|
they can either get it live or read it from a file, which is transparent to us. |
147
|
|
|
|
|
|
|
This makes it easy to make programs that allow the user to "come back later" and |
148
|
|
|
|
|
|
|
continue editing where they left off, or to seed a form with initial values. |
149
|
|
|
|
|
|
|
(Field definitions can also contain initial values.) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Based on the provided field definitions, this module can do some limited user |
152
|
|
|
|
|
|
|
input checking, and automatically generate error messages and help text beside |
153
|
|
|
|
|
|
|
the appropriate form fields when html is generated, so to show the user exactly |
154
|
|
|
|
|
|
|
what they have to fix. The "error state" for each field is stored in a hash, |
155
|
|
|
|
|
|
|
which the calling code can obtain and edit using invalid_input(), so that results |
156
|
|
|
|
|
|
|
of its own input checking routines are reflected in the new form. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This class also provides utility methods that you can use to create form field |
159
|
|
|
|
|
|
|
definitions that, when fed back to this class, generates field html that can be |
160
|
|
|
|
|
|
|
used by CGI scripts to allow users with their web browsers to define other form |
161
|
|
|
|
|
|
|
definitions for use with this class. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Note that this class is a subclass of Class::ParamParser, and inherits |
164
|
|
|
|
|
|
|
all of its methods, "params_to_hash()" and "params_to_array()". |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 RECOGNIZED FORM FIELD TYPES |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This class recognizes 10 form field types, and a complete field of that type can |
169
|
|
|
|
|
|
|
be made either by providing a "field definition" with the same "type" attribute |
170
|
|
|
|
|
|
|
value, or by calling a method with the same name as the field type. Likewise, |
171
|
|
|
|
|
|
|
groups of related form fields can be made with either a single field definition |
172
|
|
|
|
|
|
|
or method call, for all of those field types. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Standalone fields of the following types are recognized: |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=over 4 |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item 0 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
B - makes a reset button |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item 0 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
B - makes a submit button |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item 0 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
B - makes a hidden field, which the user won't see |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item 0 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
B - makes a text entry field, one row high |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item 0 |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
B - same as textfield except contents are bulleted out |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item 0 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
B |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item 0 |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
B - makes a standalone check box |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item 0 |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
B - makes a standalone radio button |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item 0 |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
B - makes a popup menu, one item can be selected at once |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item 0 |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
B - makes a scrolling list, multiple selections possible |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Groups of related fields of the following types are recognized: |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=over 4 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item 0 |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
B - makes a group of related reset buttons |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item 0 |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
B - makes a group of related submit buttons |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item 0 |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
B - makes a group of related hidden fields |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item 0 |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
B - makes a group of related text entry fields |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item 0 |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
B - makes a group of related password fields |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item 0 |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
B - makes a group of related big text entry fields |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item 0 |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
B - makes a group of related checkboxes |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item 0 |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
B - makes a group of related radio buttons |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item 0 |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
B - makes a group of related popup menus |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item 0 |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
B - makes a group of related scrolling lists |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=back |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Other field types aren't intrinsically recognized, but can still be generated as |
267
|
|
|
|
|
|
|
ordinary html tags by using methods of the HTML::EasyTags class. A list of all |
268
|
|
|
|
|
|
|
the valid field types is returned by the valid_field_type_list() method. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 BUGS |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
There is a known issue where the W3C html validator has problems with the |
273
|
|
|
|
|
|
|
generated form code, such as saying hidden fields aren't allowed where they |
274
|
|
|
|
|
|
|
are put, as well as saying that "input" tags should be in a pair. Hopefully a |
275
|
|
|
|
|
|
|
solution for these issues will present itself soon and be in the next release. |
276
|
|
|
|
|
|
|
However, web browsers like Netscape 4.08 still display the HTML properly. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head1 OUTPUT FROM SYNOPSIS PROGRAM |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head2 This HTML code is from the first time the program runs: |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
A Simple Example |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
A Simple Example |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
=head2 This HTML code is the result page of clicking the submit button: |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
A Simple Example |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
A Simple Example |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
| |
387
|
|
|
|
|
|
|
What's your name?: | This Is My Name |
388
|
|
|
|
|
|
|
| |
389
|
|
|
|
|
|
|
What's the combination?: | eenie minie |
390
|
|
|
|
|
|
|
| |
391
|
|
|
|
|
|
|
What's your favorite colour?: | red |
392
|
|
|
|
|
|
|
| Your favorites were emailed. |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
=head2 This text is the content of the email message that the program sent: |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
Date: Mon, 3 Sep 2001 13:28:19 -0700 |
400
|
|
|
|
|
|
|
To: perl@DarrenDuncan.net |
401
|
|
|
|
|
|
|
From: perl@DarrenDuncan.net |
402
|
|
|
|
|
|
|
Subject: A Simple Example HTML::FormTemplate Submission |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
Q: What's your name? |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
This Is My Name |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
****************************** |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
Q: What's the combination? |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
eenie |
414
|
|
|
|
|
|
|
minie |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
****************************** |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
Q: What's your favorite colour? |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
red |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=cut |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
###################################################################### |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
# Names of properties for objects of this class are declared here: |
427
|
|
|
|
|
|
|
my $KEY_TAG_MAKER = 'tag_maker'; # store HTML::EasyTags object |
428
|
|
|
|
|
|
|
my $KEY_AUTO_POSIT = 'auto_posit'; # with methods whose parameters |
429
|
|
|
|
|
|
|
# could be either named or positional, when we aren't sure what we |
430
|
|
|
|
|
|
|
# are given, do we guess positional? Default is named. |
431
|
|
|
|
|
|
|
my $KEY_FIELD_INPUT = 'field_input'; # an mvh w user input |
432
|
|
|
|
|
|
|
my $KEY_NEW_FORM = 'new_form'; # true when form used first time |
433
|
|
|
|
|
|
|
my $KEY_IS_SUBMIT = 'is_submit'; # ffn we check ui for to see if form submitted |
434
|
|
|
|
|
|
|
my $KEY_DEF_FF_TYPE = 'def_ff_type'; # default field type when not specified |
435
|
|
|
|
|
|
|
my $KEY_DEF_FF_NAME = 'def_ff_name'; # default field name (prefix) when not spec |
436
|
|
|
|
|
|
|
my $KEY_SUBMIT_URL = 'submit_url'; # where form goes when submitted |
437
|
|
|
|
|
|
|
my $KEY_SUBMIT_MET = 'submit_method'; # ususlly POST or GET |
438
|
|
|
|
|
|
|
my $KEY_FIELD_DEFNA = 'field_defna'; # an array of field descriptions |
439
|
|
|
|
|
|
|
my $KEY_NORMALIZED = 'normalized'; # are stored field defn in proper form? |
440
|
|
|
|
|
|
|
my $KEY_FIELD_RENDE = 'field_rende'; # a hash w rendered field html |
441
|
|
|
|
|
|
|
my $KEY_FIELD_INVAL = 'field_inval'; # a hash w shows invalid user input |
442
|
|
|
|
|
|
|
my $KEY_INVAL_MARK = 'inval_mark'; # appears by fields with invalid input |
443
|
|
|
|
|
|
|
my $KEY_ISREQ_MARK = 'isreq_mark'; # appears by fields that must be filled in |
444
|
|
|
|
|
|
|
my $KEY_PRIVA_MARK = 'priva_mark'; # appears by fields marked as private |
445
|
|
|
|
|
|
|
my $KEY_EMP_ECH_STR = 'emp_ech_str'; # string to show in place of empty field |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# Keys for items in form property $KEY_FIELD_DEFNA: |
448
|
|
|
|
|
|
|
my $FKEY_TYPE = 'type'; # actual type of input field |
449
|
|
|
|
|
|
|
my $FKEY_NAME = 'name'; # actual name of input field |
450
|
|
|
|
|
|
|
my $FKEY_VALUES = 'values'; # actual list selection options |
451
|
|
|
|
|
|
|
my $FKEY_DEFAULTS = 'defaults'; # default user selections/input |
452
|
|
|
|
|
|
|
my $FKEY_OVERRIDE = 'override'; # force coded default values to be used |
453
|
|
|
|
|
|
|
my $FKEY_LABELS = 'labels'; # visible labels of list selection options |
454
|
|
|
|
|
|
|
my $FKEY_NOLABELS = 'nolabels'; # selection options always have no labels |
455
|
|
|
|
|
|
|
my $FKEY_TAG_ATTR = 'tag_attr'; # hash of miscellaneous html tag attributes |
456
|
|
|
|
|
|
|
my $FKEY_MIN_GRP_COUNT = 'min_grp_count'; # num to set count of group members |
457
|
|
|
|
|
|
|
my $FKEY_LIST = 'list'; # force field groups to ret as list inst of scalar |
458
|
|
|
|
|
|
|
my $FKEY_LINEBREAK = 'linebreak'; # make field groups join with linebreaks |
459
|
|
|
|
|
|
|
my $FKEY_TABLE_COLS = 'table_cols'; # put field groups in table with n columns |
460
|
|
|
|
|
|
|
my $FKEY_TABLE_ROWS = 'table_rows'; # use table with n rows; ign if tcols defin |
461
|
|
|
|
|
|
|
my $FKEY_TABLE_ACRF = 'table_acrf'; # order fields across first (down if false) |
462
|
|
|
|
|
|
|
my $FKEY_IS_REQUIRED = 'is_required'; # field must be filled in (any mem) |
463
|
|
|
|
|
|
|
my $FKEY_REQ_MIN_COUNT = 'req_min_count'; # need min this many grp mem filled in |
464
|
|
|
|
|
|
|
my $FKEY_REQ_MAX_COUNT = 'req_max_count'; # need max this many grp mem filled in |
465
|
|
|
|
|
|
|
my $FKEY_REQ_OPT_MATCH = 'req_opt_match'; # bool; check if input valid select opt |
466
|
|
|
|
|
|
|
my $FKEY_VALIDATION_RULE = 'validation_rule'; # a regular expression for all mem |
467
|
|
|
|
|
|
|
my $FKEY_VISIBLE_TITLE = 'visible_title'; # main title/prompt for field |
468
|
|
|
|
|
|
|
my $FKEY_HELP_MESSAGE = 'help_message'; # suggestions for field use |
469
|
|
|
|
|
|
|
my $FKEY_ERROR_MESSAGE = 'error_message'; # appears when input invalid |
470
|
|
|
|
|
|
|
my $FKEY_STR_ABOVE_INPUT = 'str_above_input'; # str adjacent before input field |
471
|
|
|
|
|
|
|
my $FKEY_STR_BELOW_INPUT = 'str_below_input'; # str adjacent after input field |
472
|
|
|
|
|
|
|
my $FKEY_IS_PRIVATE = 'is_private'; # field not shared with public |
473
|
|
|
|
|
|
|
my $FKEY_EXCLUDE_IN_ECHO = 'exclude_in_echo'; # always exclude from reports |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
# List of "special" attributes of a form field definition; these all have formal |
476
|
|
|
|
|
|
|
# keys in their names; any attributes not in this list are misc html tag attribs |
477
|
|
|
|
|
|
|
my @SPECIAL_ATTRIB = ($FKEY_TYPE, $FKEY_NAME, $FKEY_VALUES, $FKEY_DEFAULTS, |
478
|
|
|
|
|
|
|
$FKEY_OVERRIDE, $FKEY_LABELS, $FKEY_NOLABELS, $FKEY_TAG_ATTR, |
479
|
|
|
|
|
|
|
$FKEY_MIN_GRP_COUNT, $FKEY_LIST, $FKEY_LINEBREAK, $FKEY_TABLE_COLS, |
480
|
|
|
|
|
|
|
$FKEY_TABLE_ROWS, $FKEY_TABLE_ACRF, $FKEY_IS_REQUIRED, $FKEY_REQ_MIN_COUNT, |
481
|
|
|
|
|
|
|
$FKEY_REQ_MAX_COUNT, $FKEY_REQ_OPT_MATCH, $FKEY_VALIDATION_RULE, |
482
|
|
|
|
|
|
|
$FKEY_VISIBLE_TITLE, $FKEY_HELP_MESSAGE, $FKEY_ERROR_MESSAGE, |
483
|
|
|
|
|
|
|
$FKEY_STR_ABOVE_INPUT, $FKEY_STR_BELOW_INPUT, $FKEY_IS_PRIVATE, |
484
|
|
|
|
|
|
|
$FKEY_EXCLUDE_IN_ECHO); |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
# Declare handlers for different form field types |
487
|
|
|
|
|
|
|
my %FIELD_TYPES = (); |
488
|
|
|
|
|
|
|
my $TKEY_VISIBL = 'visibl'; # a boolean - is this field user-visible or not |
489
|
|
|
|
|
|
|
my $TKEY_EDITAB = 'editab'; # a boolean - can user set value by typing or select |
490
|
|
|
|
|
|
|
my $TKEY_SELECT = 'select'; # a boolean - does the user select from list |
491
|
|
|
|
|
|
|
my $TKEY_FLDGRP = 'fldgrp'; # a boolean - is this a field group or not |
492
|
|
|
|
|
|
|
my $TKEY_MULTIV = 'multiv'; # a boolean - can field use >1 member of VALUES arg |
493
|
|
|
|
|
|
|
my $TKEY_METHOD = 'method'; # a scalar - what method to use for html rendering |
494
|
|
|
|
|
|
|
my $TKEY_PARSER = 'parser'; # always a 3-element array - for parsing definitions |
495
|
|
|
|
|
|
|
my $TKEY_ATTRIB = 'attrib'; # an array - valid defin attribs for this type |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
# First set the 6 simpler %FIELD_TYPES atributes: |
498
|
|
|
|
|
|
|
# visible, editable, selectable, field group, multivalued, rendering method |
499
|
|
|
|
|
|
|
{ |
500
|
|
|
|
|
|
|
foreach my $type (qw( reset submit hidden textfield password_field textarea |
501
|
|
|
|
|
|
|
checkbox radio popup_menu scrolling_list )) { |
502
|
|
|
|
|
|
|
$FIELD_TYPES{$type} = { |
503
|
|
|
|
|
|
|
$TKEY_VISIBL => 1, # true with 9/10, not hidden |
504
|
|
|
|
|
|
|
$TKEY_EDITAB => 1, # true with 7/10, not reset submit hidden |
505
|
|
|
|
|
|
|
$TKEY_SELECT => 0, # true with 6/10, not check radio popup scroll |
506
|
|
|
|
|
|
|
$TKEY_FLDGRP => 0, # true with 10/10 |
507
|
|
|
|
|
|
|
$TKEY_MULTIV => 0, # true with 8/10, not popup scroll |
508
|
|
|
|
|
|
|
$TKEY_METHOD => '_make_input_html', # true with 7/10, n txa pop scr |
509
|
|
|
|
|
|
|
}; |
510
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"} = { |
511
|
|
|
|
|
|
|
$TKEY_VISIBL => 1, # true with 9/10, not hidden |
512
|
|
|
|
|
|
|
$TKEY_EDITAB => 1, # true with 7/10, not reset, submit, hidden |
513
|
|
|
|
|
|
|
$TKEY_SELECT => 0, # true with 6/10, not check radio popup scroll |
514
|
|
|
|
|
|
|
$TKEY_FLDGRP => 1, # true with 10/10 |
515
|
|
|
|
|
|
|
$TKEY_MULTIV => 1, # true with 10/10 |
516
|
|
|
|
|
|
|
$TKEY_METHOD => '_make_input_group_html', # true with 7/10, n ... |
517
|
|
|
|
|
|
|
}; |
518
|
|
|
|
|
|
|
} |
519
|
|
|
|
|
|
|
foreach my $type (qw( hidden )) { |
520
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_VISIBL} = 0; |
521
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_VISIBL} = 0; |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
foreach my $type (qw( reset submit hidden )) { |
524
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_EDITAB} = 0; |
525
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_EDITAB} = 0; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
foreach my $type (qw( checkbox radio popup_menu scrolling_list )) { |
528
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_SELECT} = 1; |
529
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_SELECT} = 1; |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
foreach my $type (qw( popup_menu scrolling_list )) { |
532
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_MULTIV} = 1; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
foreach my $type (qw( textarea )) { |
535
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_METHOD} = '_make_textarea_html'; |
536
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_METHOD} = '_make_textarea_group_html'; |
537
|
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
|
foreach my $type (qw( popup_menu scrolling_list )) { |
539
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_METHOD} = '_make_select_html'; |
540
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_METHOD} = '_make_select_group_html'; |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
# Next set the input parser attribute of %FIELD_TYPES: |
545
|
|
|
|
|
|
|
{ |
546
|
|
|
|
|
|
|
foreach my $type (qw( reset submit )) { |
547
|
|
|
|
|
|
|
my $names = [ $FKEY_NAME, $FKEY_DEFAULTS ]; |
548
|
|
|
|
|
|
|
my $rename = { |
549
|
|
|
|
|
|
|
'values' => $FKEY_DEFAULTS, value => $FKEY_DEFAULTS, |
550
|
|
|
|
|
|
|
labels => $FKEY_DEFAULTS, label => $FKEY_DEFAULTS, |
551
|
|
|
|
|
|
|
}; |
552
|
|
|
|
|
|
|
my $rem = ''; |
553
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
554
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
foreach my $type (qw( hidden )) { |
557
|
|
|
|
|
|
|
my $names = [ $FKEY_NAME, $FKEY_DEFAULTS ]; |
558
|
|
|
|
|
|
|
my $rename = { |
559
|
|
|
|
|
|
|
'values' => $FKEY_DEFAULTS, value => $FKEY_DEFAULTS, |
560
|
|
|
|
|
|
|
}; |
561
|
|
|
|
|
|
|
my $rem = ''; |
562
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
563
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
foreach my $type (qw( textfield password_field )) { |
566
|
|
|
|
|
|
|
my $names = [ $FKEY_NAME, $FKEY_DEFAULTS, 'size', 'maxlength' ]; |
567
|
|
|
|
|
|
|
my $names_group = [ $FKEY_NAME, $FKEY_DEFAULTS, |
568
|
|
|
|
|
|
|
$FKEY_LINEBREAK, 'size', 'maxlength' ]; |
569
|
|
|
|
|
|
|
my $rename = { |
570
|
|
|
|
|
|
|
'values' => $FKEY_DEFAULTS, value => $FKEY_DEFAULTS, |
571
|
|
|
|
|
|
|
}; |
572
|
|
|
|
|
|
|
my $rem = ''; |
573
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
574
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_PARSER} = |
575
|
|
|
|
|
|
|
[$names_group, $rename, $rem]; |
576
|
|
|
|
|
|
|
} |
577
|
|
|
|
|
|
|
foreach my $type (qw( textarea )) { |
578
|
|
|
|
|
|
|
my $names = [ $FKEY_NAME, $FKEY_DEFAULTS, 'rows', 'cols' ]; |
579
|
|
|
|
|
|
|
my $names_group = [ $FKEY_NAME, $FKEY_DEFAULTS, |
580
|
|
|
|
|
|
|
$FKEY_LINEBREAK, 'rows', 'cols' ]; |
581
|
|
|
|
|
|
|
my $rename = { |
582
|
|
|
|
|
|
|
'values' => $FKEY_DEFAULTS, value => $FKEY_DEFAULTS, |
583
|
|
|
|
|
|
|
text => $FKEY_DEFAULTS, columns => 'cols', |
584
|
|
|
|
|
|
|
}; |
585
|
|
|
|
|
|
|
my $rem = $FKEY_DEFAULTS; |
586
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
587
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_PARSER} = |
588
|
|
|
|
|
|
|
[$names_group, $rename, $rem]; |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
foreach my $type (qw( checkbox radio popup_menu scrolling_list )) { |
591
|
|
|
|
|
|
|
my $names = [ $FKEY_NAME, $FKEY_DEFAULTS, $FKEY_VALUES, $FKEY_LABELS ]; |
592
|
|
|
|
|
|
|
my $names_group = [ $FKEY_NAME, $FKEY_VALUES, $FKEY_DEFAULTS, |
593
|
|
|
|
|
|
|
$FKEY_LINEBREAK, $FKEY_LABELS ]; |
594
|
|
|
|
|
|
|
my $rename = { |
595
|
|
|
|
|
|
|
value => $FKEY_VALUES, checked => $FKEY_DEFAULTS, |
596
|
|
|
|
|
|
|
selected => $FKEY_DEFAULTS, on => $FKEY_DEFAULTS, |
597
|
|
|
|
|
|
|
label => $FKEY_LABELS, text => $FKEY_LABELS, |
598
|
|
|
|
|
|
|
}; |
599
|
|
|
|
|
|
|
my $rem = $FKEY_LABELS; |
600
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_PARSER} = [$names, $rename, $rem]; |
601
|
|
|
|
|
|
|
$FIELD_TYPES{$type."_group"}->{$TKEY_PARSER} = |
602
|
|
|
|
|
|
|
[$names_group, $rename, $rem]; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
foreach my $type (keys %FIELD_TYPES) { |
605
|
|
|
|
|
|
|
my $rename = $FIELD_TYPES{$type}->{$TKEY_PARSER}->[1]; |
606
|
|
|
|
|
|
|
$rename->{default} = $FKEY_DEFAULTS; |
607
|
|
|
|
|
|
|
$rename->{nolabel} = $FKEY_NOLABELS; |
608
|
|
|
|
|
|
|
$rename->{force} = $FKEY_OVERRIDE; |
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
foreach my $type (qw( checkbox_group radio_group )) { |
611
|
|
|
|
|
|
|
my $rename = $FIELD_TYPES{$type}->{$TKEY_PARSER}->[1]; |
612
|
|
|
|
|
|
|
$rename->{cols} = $FKEY_TABLE_COLS; |
613
|
|
|
|
|
|
|
$rename->{columns} = $FKEY_TABLE_COLS; |
614
|
|
|
|
|
|
|
$rename->{rows} = $FKEY_TABLE_ROWS; |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
# Next set the valid-attributes attribute of %FIELD_TYPES: |
619
|
|
|
|
|
|
|
{ |
620
|
|
|
|
|
|
|
foreach my $type (keys %FIELD_TYPES) { |
621
|
|
|
|
|
|
|
my $typerec = $FIELD_TYPES{$type}; |
622
|
|
|
|
|
|
|
my @attrib = ($FKEY_TYPE, $FKEY_NAME, $FKEY_DEFAULTS, $FKEY_OVERRIDE, |
623
|
|
|
|
|
|
|
$FKEY_TAG_ATTR, $FKEY_IS_REQUIRED, $FKEY_REQ_OPT_MATCH, |
624
|
|
|
|
|
|
|
$FKEY_VALIDATION_RULE, $FKEY_VISIBLE_TITLE, $FKEY_HELP_MESSAGE, |
625
|
|
|
|
|
|
|
$FKEY_ERROR_MESSAGE, $FKEY_STR_ABOVE_INPUT, $FKEY_STR_BELOW_INPUT, |
626
|
|
|
|
|
|
|
$FKEY_IS_PRIVATE, $FKEY_EXCLUDE_IN_ECHO); |
627
|
|
|
|
|
|
|
if( $typerec->{$TKEY_FLDGRP} ) { |
628
|
|
|
|
|
|
|
push( @attrib, $FKEY_MIN_GRP_COUNT, $FKEY_LIST, $FKEY_LINEBREAK, |
629
|
|
|
|
|
|
|
$FKEY_TABLE_COLS, $FKEY_TABLE_ROWS, $FKEY_TABLE_ACRF, |
630
|
|
|
|
|
|
|
$FKEY_REQ_MIN_COUNT, $FKEY_REQ_MAX_COUNT ); |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
$typerec->{$TKEY_ATTRIB} = \@attrib; |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
foreach my $type (qw( checkbox radio popup_menu scrolling_list )) { |
635
|
|
|
|
|
|
|
my @attrib = ($FKEY_VALUES, $FKEY_LABELS); |
636
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}, @attrib ); |
637
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type."_group"}->{$TKEY_ATTRIB}}, @attrib ); |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
foreach my $type (qw( checkbox radio )) { |
640
|
|
|
|
|
|
|
my @attrib = ($FKEY_NOLABELS); |
641
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}, @attrib ); |
642
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type."_group"}->{$TKEY_ATTRIB}}, @attrib ); |
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
foreach my $type (qw( textfield password_field )) { |
645
|
|
|
|
|
|
|
my @attrib = ('size', 'maxlength'); |
646
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}, @attrib ); |
647
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type."_group"}->{$TKEY_ATTRIB}}, @attrib ); |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
foreach my $type (qw( textarea )) { |
650
|
|
|
|
|
|
|
my @attrib = ('rows', 'cols'); |
651
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}, @attrib ); |
652
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type."_group"}->{$TKEY_ATTRIB}}, @attrib ); |
653
|
|
|
|
|
|
|
} |
654
|
|
|
|
|
|
|
foreach my $type (qw( scrolling_list )) { |
655
|
|
|
|
|
|
|
my @attrib = ('size', 'multiple'); |
656
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}, @attrib ); |
657
|
|
|
|
|
|
|
push( @{$FIELD_TYPES{$type."_group"}->{$TKEY_ATTRIB}}, @attrib ); |
658
|
|
|
|
|
|
|
} |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
# Used by _make_input_html() to convert our field types to actual |
662
|
|
|
|
|
|
|
# tag TYPE arguments. |
663
|
|
|
|
|
|
|
my %INPUT_TAG_IMPL_TYPE = ( |
664
|
|
|
|
|
|
|
'reset' => 'reset', |
665
|
|
|
|
|
|
|
submit => 'submit', |
666
|
|
|
|
|
|
|
hidden => 'hidden', |
667
|
|
|
|
|
|
|
textfield => 'text', |
668
|
|
|
|
|
|
|
password_field => 'password', |
669
|
|
|
|
|
|
|
checkbox => 'checkbox', |
670
|
|
|
|
|
|
|
radio => 'radio', |
671
|
|
|
|
|
|
|
reset_group => 'reset', |
672
|
|
|
|
|
|
|
submit_group => 'submit', |
673
|
|
|
|
|
|
|
hidden_group => 'hidden', |
674
|
|
|
|
|
|
|
textfield_group => 'text', |
675
|
|
|
|
|
|
|
password_field_group => 'password', |
676
|
|
|
|
|
|
|
checkbox_group => 'checkbox', |
677
|
|
|
|
|
|
|
radio_group => 'radio', |
678
|
|
|
|
|
|
|
); |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
###################################################################### |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=head1 SYNTAX |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
This class does not export any functions or methods, so you need to call them |
685
|
|
|
|
|
|
|
using object notation. This means using Bfunction()> for functions |
686
|
|
|
|
|
|
|
and B<$object-Emethod()> for methods. If you are inheriting this class for |
687
|
|
|
|
|
|
|
your own modules, then that often means something like B<$self-Emethod()>. |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
Methods of this class always "return" their results, rather than printing them |
690
|
|
|
|
|
|
|
out to a file or the screen. Not only is this simpler, but it gives the calling |
691
|
|
|
|
|
|
|
code the maximum amount of control over what happens in the program. They may |
692
|
|
|
|
|
|
|
wish to do post-processing with the generated HTML, or want to output it in a |
693
|
|
|
|
|
|
|
different order than it is generated. |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
=head1 CONSTRUCTOR FUNCTIONS AND METHODS |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=head2 new() |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
This function creates a new HTML::FormTemplate object and returns it. |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=cut |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
###################################################################### |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
sub new { |
706
|
2
|
|
|
2
|
1
|
115
|
my $class = shift( @_ ); |
707
|
2
|
|
33
|
|
|
16
|
my $self = bless( {}, ref($class) || $class ); |
708
|
2
|
|
|
|
|
8
|
$self->initialize( @_ ); |
709
|
2
|
|
|
|
|
4
|
return( $self ); |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
###################################################################### |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
=head2 initialize() |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
This method is used by B to set the initial properties of an object, |
717
|
|
|
|
|
|
|
that it creates. |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
=cut |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
###################################################################### |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
sub initialize { |
724
|
2
|
|
|
2
|
1
|
4
|
my ($self) = @_; |
725
|
2
|
|
|
|
|
12
|
$self->{$KEY_TAG_MAKER} = HTML::EasyTags->new(); |
726
|
2
|
|
|
|
|
44
|
$self->{$KEY_AUTO_POSIT} = 0; |
727
|
2
|
|
|
|
|
19
|
$self->{$KEY_FIELD_INPUT} = CGI::MultiValuedHash->new(); |
728
|
2
|
|
|
|
|
44
|
$self->{$KEY_NEW_FORM} = 1; |
729
|
2
|
|
|
|
|
7
|
$self->{$KEY_IS_SUBMIT} = '.is_submit'; |
730
|
2
|
|
|
|
|
6
|
$self->{$KEY_DEF_FF_TYPE} = 'textfield'; |
731
|
2
|
|
|
|
|
5
|
$self->{$KEY_DEF_FF_NAME} = 'nonamefield'; |
732
|
2
|
|
|
|
|
6
|
$self->{$KEY_SUBMIT_URL} = 'http://127.0.0.1'; |
733
|
2
|
|
|
|
|
4
|
$self->{$KEY_SUBMIT_MET} = 'post'; |
734
|
2
|
|
|
|
|
6
|
$self->{$KEY_FIELD_DEFNA} = []; |
735
|
2
|
|
|
|
|
7
|
$self->{$KEY_NORMALIZED} = 0; |
736
|
2
|
|
|
|
|
6
|
$self->{$KEY_FIELD_RENDE} = undef; |
737
|
2
|
|
|
|
|
4
|
$self->{$KEY_FIELD_INVAL} = undef; |
738
|
2
|
|
|
|
|
51
|
$self->{$KEY_INVAL_MARK} = '?'; |
739
|
2
|
|
|
|
|
5
|
$self->{$KEY_ISREQ_MARK} = '*'; |
740
|
2
|
|
|
|
|
8
|
$self->{$KEY_PRIVA_MARK} = '~'; |
741
|
2
|
|
|
|
|
6
|
$self->{$KEY_EMP_ECH_STR} = ''; |
742
|
|
|
|
|
|
|
} |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
###################################################################### |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=head2 clone([ CLONE ]) |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
This method initializes a new object to have all of the same properties of the |
749
|
|
|
|
|
|
|
current object and returns it. This new object can be provided in the optional |
750
|
|
|
|
|
|
|
argument CLONE (if CLONE is an object of the same class as the current object); |
751
|
|
|
|
|
|
|
otherwise, a brand new object of the current class is used. Only object |
752
|
|
|
|
|
|
|
properties recognized by HTML::FormTemplate are set in the clone; other properties |
753
|
|
|
|
|
|
|
are not changed. |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
=cut |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
###################################################################### |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
sub clone { |
760
|
0
|
|
|
0
|
1
|
|
my ($self, $clone) = @_; |
761
|
0
|
0
|
|
|
|
|
ref($clone) eq ref($self) or $clone = bless( {}, ref($self) ); |
762
|
|
|
|
|
|
|
|
763
|
0
|
|
|
|
|
|
$clone->{$KEY_TAG_MAKER} = $self->{$KEY_TAG_MAKER}->clone(); |
764
|
|
|
|
|
|
|
|
765
|
0
|
|
|
|
|
|
$clone->{$KEY_AUTO_POSIT} = $self->{$KEY_AUTO_POSIT}; |
766
|
|
|
|
|
|
|
|
767
|
0
|
|
|
|
|
|
$clone->{$KEY_FIELD_INPUT} = $self->{$KEY_FIELD_INPUT}->clone(); |
768
|
|
|
|
|
|
|
|
769
|
0
|
|
|
|
|
|
$clone->{$KEY_NEW_FORM} = $self->{$KEY_NEW_FORM}; |
770
|
0
|
|
|
|
|
|
$clone->{$KEY_IS_SUBMIT} = $self->{$KEY_IS_SUBMIT}; |
771
|
0
|
|
|
|
|
|
$clone->{$KEY_DEF_FF_TYPE} = $self->{$KEY_DEF_FF_TYPE}; |
772
|
0
|
|
|
|
|
|
$clone->{$KEY_DEF_FF_NAME} = $self->{$KEY_DEF_FF_NAME}; |
773
|
0
|
|
|
|
|
|
$clone->{$KEY_SUBMIT_URL} = $self->{$KEY_SUBMIT_URL}; |
774
|
0
|
|
|
|
|
|
$clone->{$KEY_SUBMIT_MET} = $self->{$KEY_SUBMIT_MET}; |
775
|
|
|
|
|
|
|
|
776
|
0
|
|
|
|
|
|
$clone->{$KEY_FIELD_DEFNA} = |
777
|
0
|
|
|
|
|
|
[map { $_->clone() } @{$self->{$KEY_FIELD_DEFNA}}]; |
|
0
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
|
779
|
0
|
|
|
|
|
|
$clone->{$KEY_NORMALIZED} = $self->{$KEY_NORMALIZED}; |
780
|
|
|
|
|
|
|
|
781
|
0
|
|
|
|
|
|
defined( $self->{$KEY_FIELD_RENDE} ) and |
782
|
0
|
0
|
|
|
|
|
$clone->{$KEY_FIELD_RENDE} = {%{$self->{$KEY_FIELD_RENDE}}}; |
783
|
|
|
|
|
|
|
|
784
|
0
|
|
|
|
|
|
defined( $self->{$KEY_FIELD_INVAL} ) and |
785
|
0
|
0
|
|
|
|
|
$clone->{$KEY_FIELD_INVAL} = {%{$self->{$KEY_FIELD_INVAL}}}; |
786
|
|
|
|
|
|
|
|
787
|
0
|
|
|
|
|
|
$clone->{$KEY_INVAL_MARK} = $self->{$KEY_INVAL_MARK}; |
788
|
0
|
|
|
|
|
|
$clone->{$KEY_ISREQ_MARK} = $self->{$KEY_ISREQ_MARK}; |
789
|
0
|
|
|
|
|
|
$clone->{$KEY_PRIVA_MARK} = $self->{$KEY_PRIVA_MARK}; |
790
|
0
|
|
|
|
|
|
$clone->{$KEY_EMP_ECH_STR} = $self->{$KEY_EMP_ECH_STR}; |
791
|
|
|
|
|
|
|
|
792
|
0
|
|
|
|
|
|
return( $clone ); |
793
|
|
|
|
|
|
|
} |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
###################################################################### |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
=head2 positional_by_default([ VALUE ]) |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
This method is an accessor for the boolean "positional arguments" property of |
800
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
801
|
|
|
|
|
|
|
With methods whose parameters could be either named or positional, when we aren't |
802
|
|
|
|
|
|
|
sure what we are given, do we guess positional? Default is named. |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
=cut |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
###################################################################### |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
sub positional_by_default { |
809
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
810
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
811
|
0
|
|
|
|
|
|
$self->{$KEY_AUTO_POSIT} = $new_value; |
812
|
|
|
|
|
|
|
} |
813
|
0
|
|
|
|
|
|
return( $self->{$KEY_AUTO_POSIT} ); |
814
|
|
|
|
|
|
|
} |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
###################################################################### |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
=head1 METHODS FOR SETTING USER INPUT AND NEW FORM STATUS |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
=head2 reset_to_new_form() |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
This method sets the boolean property "new form" to true, wipes out any user |
823
|
|
|
|
|
|
|
input (putting form to factory defaults), and clears all error conditions. You |
824
|
|
|
|
|
|
|
can use this method to implement your own "defaults" button if you wish. |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
=cut |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
###################################################################### |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
sub reset_to_new_form { |
831
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
832
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INPUT} = CGI::MultiValuedHash->new(); |
833
|
0
|
|
|
|
|
|
$self->{$KEY_NEW_FORM} = 1; |
834
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = undef; |
835
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = undef; |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
###################################################################### |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
=head2 user_input([ INPUT ]) |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
This method is an accessor for the "user input" property of this object, which it |
843
|
|
|
|
|
|
|
returns. If INPUT is defined, this property is set to it. This property is a |
844
|
|
|
|
|
|
|
single MultiValuedHash object or HASH ref whose keys are the form fields that the |
845
|
|
|
|
|
|
|
user filled in and whose values are what they entered. These values are used |
846
|
|
|
|
|
|
|
when creating form field html to preserve what the user previously entered, and |
847
|
|
|
|
|
|
|
they are used when doing our own input checking, and they are used when |
848
|
|
|
|
|
|
|
generating input echo reports. This property is also examined when it is set and |
849
|
|
|
|
|
|
|
automatically changes the "new form" property accordingly. The property is |
850
|
|
|
|
|
|
|
undefined by default. The method also clears any error conditions. |
851
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
=cut |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
###################################################################### |
855
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
sub user_input { |
857
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
858
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
859
|
0
|
|
|
|
|
|
$new_value = CGI::MultiValuedHash->new( 0, $new_value ); |
860
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INPUT} = $new_value; |
861
|
0
|
|
|
|
|
|
$self->{$KEY_NEW_FORM} = |
862
|
|
|
|
|
|
|
!$new_value->fetch_value( $self->{$KEY_IS_SUBMIT} ); |
863
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = undef; |
864
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = undef; |
865
|
|
|
|
|
|
|
} |
866
|
0
|
|
|
|
|
|
return( $self->{$KEY_FIELD_INPUT} ); |
867
|
|
|
|
|
|
|
} |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
###################################################################### |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
=head2 new_form([ VALUE ]) |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
This method is an accessor for the boolean "new form" property of this object, |
874
|
|
|
|
|
|
|
which it returns. If VALUE is defined, this property is set to it. If this |
875
|
|
|
|
|
|
|
property is true, then we act like this is the first time we were called. That |
876
|
|
|
|
|
|
|
means that the form is blank except for factory defaults, and there are no error |
877
|
|
|
|
|
|
|
conditions. If this property is false then we are being called again after the |
878
|
|
|
|
|
|
|
user submitted the form at least once, and we do perform input checking. This |
879
|
|
|
|
|
|
|
property is true by default. No other properties are changed. |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
=cut |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
###################################################################### |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
sub new_form { |
886
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
887
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
888
|
0
|
|
|
|
|
|
$self->{$KEY_NEW_FORM} = $new_value; |
889
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = undef; |
890
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = undef; |
891
|
|
|
|
|
|
|
} |
892
|
0
|
|
|
|
|
|
return( $self->{$KEY_NEW_FORM} ); |
893
|
|
|
|
|
|
|
} |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
###################################################################### |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
=head1 METHODS FOR DEFAULT FIELD PROPERTIES |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
=head2 new_form_determinant([ VALUE ]) |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
This method is an accessor for the boolean "new form determinant" property of |
902
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
903
|
|
|
|
|
|
|
This property is the name of a field that we will scan provided user input for |
904
|
|
|
|
|
|
|
to see if this form was submitted. The default property value is ".is_submit". |
905
|
|
|
|
|
|
|
If this field has a true value in the user input, then the form is not new. |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
=cut |
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
###################################################################### |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
sub new_form_determinant { |
912
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
913
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
914
|
0
|
|
|
|
|
|
$self->{$KEY_IS_SUBMIT} = $new_value; |
915
|
|
|
|
|
|
|
} |
916
|
0
|
|
|
|
|
|
return( $self->{$KEY_IS_SUBMIT} ); |
917
|
|
|
|
|
|
|
} |
918
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
###################################################################### |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
=head2 default_field_type([ VALUE ]) |
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
This method is an accessor for the boolean "default field type" property of |
924
|
|
|
|
|
|
|
this object, which it returns. If VALUE is a valid field type, this property is |
925
|
|
|
|
|
|
|
set to it. If someone tries to make a form field without providing a valid |
926
|
|
|
|
|
|
|
field type, then this is used as the default. The default value is 'textfield'. |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
=cut |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
###################################################################### |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
sub default_field_type { |
933
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
934
|
0
|
0
|
|
|
|
|
if( $FIELD_TYPES{$new_value} ) { |
935
|
0
|
|
|
|
|
|
$self->{$KEY_DEF_FF_TYPE} = $new_value; |
936
|
|
|
|
|
|
|
} |
937
|
0
|
|
|
|
|
|
return( $self->{$KEY_DEF_FF_TYPE} ); |
938
|
|
|
|
|
|
|
} |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
###################################################################### |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
=head2 default_field_name([ VALUE ]) |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
This method is an accessor for the boolean "default field name" property of |
945
|
|
|
|
|
|
|
this object, which it returns. If VALUE is not an empty string, this property is |
946
|
|
|
|
|
|
|
set to it. If someone tries to make a form field without providing a field name, |
947
|
|
|
|
|
|
|
then this is used as the default name, or as the prefix for a numbered name |
948
|
|
|
|
|
|
|
sequence with stored fields. The default value is 'nonamefield'. |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
=cut |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
###################################################################### |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
sub default_field_name { |
955
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
956
|
0
|
0
|
|
|
|
|
if( $new_value ne '' ) { |
957
|
0
|
|
|
|
|
|
$self->{$KEY_DEF_FF_NAME} = $new_value; |
958
|
|
|
|
|
|
|
} |
959
|
0
|
|
|
|
|
|
return( $self->{$KEY_DEF_FF_NAME} ); |
960
|
|
|
|
|
|
|
} |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
###################################################################### |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
=head1 METHODS NAMED AFTER FIELD-TYPES |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
These methods have the same names as field types and each one will make HTML for |
967
|
|
|
|
|
|
|
either a single field or group of related fields of that type. Arguments can be |
968
|
|
|
|
|
|
|
in either named or positional format, or specifically any argument format that |
969
|
|
|
|
|
|
|
Class::ParamParser knows how to handle. If the parser is in doubt, it will guess |
970
|
|
|
|
|
|
|
the format based on the value you set with the positional_by_default() method. |
971
|
|
|
|
|
|
|
The one exception to this is with TYPE; please see its description further below. |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
The method listings show the positional arguments in the parenthesis beside each |
974
|
|
|
|
|
|
|
method name, and for those any use of brackets means that the enclosed arguments |
975
|
|
|
|
|
|
|
are optional. Below the method name is a vertical list of named arguments; for |
976
|
|
|
|
|
|
|
those, any group of arguments that is enclosed by a bracket-pair are all aliases |
977
|
|
|
|
|
|
|
for each other, and only one should be used at a time. For any of [value, |
978
|
|
|
|
|
|
|
default, label, nolabel] the singular and plural versions are always aliases for |
979
|
|
|
|
|
|
|
each other, and so both are not explicitely shown below. |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
There are several extra named arguments that apply to each field type which are |
982
|
|
|
|
|
|
|
not shown here; see the EXTRA FIELD-TYPE METHOD ARGUMENTS section for details. |
983
|
|
|
|
|
|
|
While the named argument "linebreak" is shown here for completeness, please see |
984
|
|
|
|
|
|
|
the other section for its explanation also. |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
=head2 reset( NAME[, DEFAULT] ) |
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
NAME |
989
|
|
|
|
|
|
|
[DEFAULT or VALUE or LABEL] |
990
|
|
|
|
|
|
|
|
991
|
|
|
|
|
|
|
This method makes a single reset button that has NAME for its name and |
992
|
|
|
|
|
|
|
optionally DEFAULT as its value. Web browsers may or may not use this value as |
993
|
|
|
|
|
|
|
a button label and they may or may not include the value with form submissions. |
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
=head2 submit( NAME[, DEFAULT] ) |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
NAME |
998
|
|
|
|
|
|
|
[DEFAULT or VALUE or LABEL] |
999
|
|
|
|
|
|
|
|
1000
|
|
|
|
|
|
|
This method makes a single submit button that has NAME for its name and |
1001
|
|
|
|
|
|
|
optionally DEFAULT as its value. Web browsers may or may not use this value as |
1002
|
|
|
|
|
|
|
a button label and they may or may not include the value with form submissions. |
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
=head2 hidden( NAME, DEFAULT ) |
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
NAME |
1007
|
|
|
|
|
|
|
[DEFAULT or VALUE] |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
This method makes a single hidden field that has NAME for its name and |
1010
|
|
|
|
|
|
|
DEFAULT as its value. Nothing is displayed visually by web browsers. |
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
=head2 textfield( NAME[, DEFAULT[, SIZE[, MAXLENGTH]]] ) |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
NAME |
1015
|
|
|
|
|
|
|
[DEFAULT or VALUE] |
1016
|
|
|
|
|
|
|
SIZE |
1017
|
|
|
|
|
|
|
MAXLENGTH |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
This method makes a single text entry field that has NAME for its name and |
1020
|
|
|
|
|
|
|
DEFAULT as its value. The field is one line high and is wide enough to display |
1021
|
|
|
|
|
|
|
SIZE characters at once. The user can enter a maximum of MAXLENGTH characters |
1022
|
|
|
|
|
|
|
if that argument is set, or is not limited otherwise. |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
=head2 password_field( NAME[, DEFAULT[, SIZE[, MAXLENGTH]]] ) |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
NAME |
1027
|
|
|
|
|
|
|
[DEFAULT or VALUE] |
1028
|
|
|
|
|
|
|
SIZE |
1029
|
|
|
|
|
|
|
MAXLENGTH |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
This method makes a single password entry field that has NAME for its name and |
1032
|
|
|
|
|
|
|
DEFAULT as its value. The arguments are the same as a textfield but the |
1033
|
|
|
|
|
|
|
displayed value is visually bulleted out by the browser. |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=head2 textarea( NAME[, DEFAULT[, ROWS[, COLS]]] ) |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
NAME |
1038
|
|
|
|
|
|
|
[DEFAULT or VALUE or TEXT] |
1039
|
|
|
|
|
|
|
ROWS |
1040
|
|
|
|
|
|
|
[COLS or COLUMNS] |
1041
|
|
|
|
|
|
|
|
1042
|
|
|
|
|
|
|
This method makes a single big text field that has NAME for its name and |
1043
|
|
|
|
|
|
|
DEFAULT as its value. The field is ROWS lines high and is wide enough to |
1044
|
|
|
|
|
|
|
display COLS characters at once. |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
=head2 checkbox( NAME[, DEFAULT[, VALUE[, LABEL]]] ) |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
NAME |
1049
|
|
|
|
|
|
|
VALUE |
1050
|
|
|
|
|
|
|
[DEFAULT or CHECKED or SELECTED or ON] |
1051
|
|
|
|
|
|
|
[LABEL or TEXT] |
1052
|
|
|
|
|
|
|
NOLABEL |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
This method makes a single checkbox that has NAME for its name and |
1055
|
|
|
|
|
|
|
VALUE as its value. VALUE defaults to 'on' if it is not defined. |
1056
|
|
|
|
|
|
|
If DEFAULT is true then the box is checked; otherwise it is not. |
1057
|
|
|
|
|
|
|
Unless NOLABEL is true, there is always a user-visible text label |
1058
|
|
|
|
|
|
|
that appears beside the checkbox. If LABEL is defined then that is used as |
1059
|
|
|
|
|
|
|
the label text; otherwise NAME is used by default. |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
=head2 radio( NAME[, DEFAULT[, VALUE[, LABEL]]] ) |
1062
|
|
|
|
|
|
|
|
1063
|
|
|
|
|
|
|
NAME |
1064
|
|
|
|
|
|
|
VALUE |
1065
|
|
|
|
|
|
|
[DEFAULT or CHECKED or SELECTED or ON] |
1066
|
|
|
|
|
|
|
[LABEL or TEXT] |
1067
|
|
|
|
|
|
|
NOLABEL |
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
This method makes a single radio option that has NAME for its name and |
1070
|
|
|
|
|
|
|
VALUE as its value. The arguments are the same as for a checkbox. |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
=head2 popup_menu( NAME, [DEFAULTS], VALUES[, LABELS] ) |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
NAME |
1075
|
|
|
|
|
|
|
VALUES |
1076
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1077
|
|
|
|
|
|
|
[LABELS or TEXT] |
1078
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
This method makes a single popup menu that has NAME for its name and option |
1080
|
|
|
|
|
|
|
values populated from the VALUES array ref argument. VALUES defaults to a |
1081
|
|
|
|
|
|
|
one-element list containing 'on' if not defined. If DEFAULTS is a hash ref |
1082
|
|
|
|
|
|
|
then its keys are matched with elements of VALUES and wherever its values are |
1083
|
|
|
|
|
|
|
true then the corresponding menu option is selected; otherwise, DEFAULTS is |
1084
|
|
|
|
|
|
|
taken as a list of option VALUES that are to be selected; by default, no |
1085
|
|
|
|
|
|
|
options are selected. Similarly, if LABELS is a hash ref then its keys are |
1086
|
|
|
|
|
|
|
matched with elements of VALUES and its values provide labels for them; |
1087
|
|
|
|
|
|
|
otherwise, LABELS is taken as a list of labels which are matched to VALUES |
1088
|
|
|
|
|
|
|
by their corresponding array indices. Since options must always have |
1089
|
|
|
|
|
|
|
user-visible labels, any one for which LABELS is undefined will default to |
1090
|
|
|
|
|
|
|
using its value as a label. Note that a popup menu is a simplified case of |
1091
|
|
|
|
|
|
|
a scrolling list where only one option can be selected and the selected option |
1092
|
|
|
|
|
|
|
is the only one visible while the field doesn't have the user's focus (the menu |
1093
|
|
|
|
|
|
|
visually opens up when the field has focus). |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
=head2 scrolling_list( NAME, [DEFAULTS], VALUES[, LABELS] ) |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
NAME |
1098
|
|
|
|
|
|
|
VALUES |
1099
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1100
|
|
|
|
|
|
|
[LABELS or TEXT] |
1101
|
|
|
|
|
|
|
SIZE |
1102
|
|
|
|
|
|
|
MULTIPLE |
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
This method makes a single scrolling list that has NAME for its name and option |
1105
|
|
|
|
|
|
|
values populated from the VALUES array ref argument. The arguments are the same |
1106
|
|
|
|
|
|
|
as for a popup menu, except that scrolling lists also support SIZE and MULTIPLE. |
1107
|
|
|
|
|
|
|
If MULTIPLE is true then the user can select multiple options; otherwise they |
1108
|
|
|
|
|
|
|
can select only one. If SIZE is a number greater than one then that number of |
1109
|
|
|
|
|
|
|
options is visually displayed at once; this argument defaults to the count of |
1110
|
|
|
|
|
|
|
elements in VALUES if false. Note that setting SIZE to 1 will cause this |
1111
|
|
|
|
|
|
|
field to be a popup menu instead. |
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
=head2 reset_group( NAME[, DEFAULTS] ) |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
NAME |
1116
|
|
|
|
|
|
|
[DEFAULTS or VALUES or LABELS] |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
This method makes a group of related reset buttons, which have NAME in common. |
1119
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
=head2 submit_group( NAME[, DEFAULTS] ) |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
NAME |
1124
|
|
|
|
|
|
|
[DEFAULTS or VALUES or LABELS] |
1125
|
|
|
|
|
|
|
|
1126
|
|
|
|
|
|
|
This method makes a group of related submit buttons, which have NAME in common. |
1127
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1128
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
=head2 hidden_group( NAME, DEFAULTS ) |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
NAME |
1132
|
|
|
|
|
|
|
[DEFAULTS or VALUES] |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
This method makes a group of related hidden fields, which have NAME in common. |
1135
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1136
|
|
|
|
|
|
|
|
1137
|
|
|
|
|
|
|
=head2 textfield_group( NAME[, DEFAULTS[, LINEBREAK[, SIZE[, MAXLENGTH]]]] ) |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
NAME |
1140
|
|
|
|
|
|
|
[DEFAULTS or VALUES] |
1141
|
|
|
|
|
|
|
SIZE |
1142
|
|
|
|
|
|
|
MAXLENGTH |
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
This method makes a group of related text entry fields, which have NAME in common. |
1145
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
=head2 password_field_group( NAME[, DEFAULTS[, LINEBREAK[, SIZE[, MAXLENGTH]]]] ) |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
NAME |
1150
|
|
|
|
|
|
|
[DEFAULTS or VALUES] |
1151
|
|
|
|
|
|
|
SIZE |
1152
|
|
|
|
|
|
|
MAXLENGTH |
1153
|
|
|
|
|
|
|
|
1154
|
|
|
|
|
|
|
This method makes a group of related password entry fields, which have NAME in common. |
1155
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
=head2 textarea_group( NAME[, DEFAULTS[, LINEBREAK[, ROWS[, COLS]]]] ) |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
NAME |
1160
|
|
|
|
|
|
|
[DEFAULTS or VALUES or TEXT] |
1161
|
|
|
|
|
|
|
ROWS |
1162
|
|
|
|
|
|
|
[COLS or COLUMNS] |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
This method makes a group of related big text fields, which have NAME in common. |
1165
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
=head2 checkbox_group( NAME, VALUES[, DEFAULTS[, LINEBREAK[, LABELS]]] ) |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
NAME |
1170
|
|
|
|
|
|
|
VALUES |
1171
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1172
|
|
|
|
|
|
|
[LABELS or TEXT] |
1173
|
|
|
|
|
|
|
NOLABELS |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
This method makes a group of related checkboxes, which have NAME in common. There |
1176
|
|
|
|
|
|
|
is one group member for each element in the array ref VALUES. VALUES defaults to |
1177
|
|
|
|
|
|
|
a one-element list containing 'on' if not defined. If DEFAULTS is a hash ref |
1178
|
|
|
|
|
|
|
then its keys are matched with elements of VALUES and wherever its values are |
1179
|
|
|
|
|
|
|
true then the corresponding box is checked; otherwise, DEFAULTS is taken as a |
1180
|
|
|
|
|
|
|
list of box VALUES that are to be checked; by default, no boxes are checked. |
1181
|
|
|
|
|
|
|
Similarly, if LABELS is a hash ref then its keys are matched with elements of |
1182
|
|
|
|
|
|
|
VALUES and its values provide labels for them; otherwise, LABELS is taken as a |
1183
|
|
|
|
|
|
|
list of labels which are matched to VALUES by their corresponding array indices. |
1184
|
|
|
|
|
|
|
Unless NOLABELS is true, there is always a user-visible text label that appears |
1185
|
|
|
|
|
|
|
beside each checkbox. Any checkbox for which LABELS is undefined will default to |
1186
|
|
|
|
|
|
|
using its value for a label. |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
=head2 radio_group( NAME, VALUES[, DEFAULTS[, LINEBREAK[, LABELS]]] ) |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
NAME |
1191
|
|
|
|
|
|
|
VALUES |
1192
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1193
|
|
|
|
|
|
|
[LABELS or TEXT] |
1194
|
|
|
|
|
|
|
NOLABELS |
1195
|
|
|
|
|
|
|
|
1196
|
|
|
|
|
|
|
This method makes a group of related radio options, which have NAME in common. |
1197
|
|
|
|
|
|
|
There is one group member for each element in the array ref VALUES. |
1198
|
|
|
|
|
|
|
The arguments are the same as for a checkbox_group. |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
=head2 popup_menu_group( NAME, VALUES[, DEFAULTS[, LINEBREAK[, LABELS]]] ) |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
NAME |
1203
|
|
|
|
|
|
|
VALUES |
1204
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1205
|
|
|
|
|
|
|
[LABELS or TEXT] |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
This method makes a group of related popup menus, which have NAME in common. |
1208
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1209
|
|
|
|
|
|
|
|
1210
|
|
|
|
|
|
|
=head2 scrolling_list_group( NAME, VALUES[, DEFAULTS[, LINEBREAK[, LABELS]]] ) |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
NAME |
1213
|
|
|
|
|
|
|
VALUES |
1214
|
|
|
|
|
|
|
[DEFAULTS or CHECKED or SELECTED or ON] |
1215
|
|
|
|
|
|
|
[LABELS or TEXT] |
1216
|
|
|
|
|
|
|
SIZE |
1217
|
|
|
|
|
|
|
MULTIPLE |
1218
|
|
|
|
|
|
|
|
1219
|
|
|
|
|
|
|
This method makes a group of related scrolling lists, which have NAME in common. |
1220
|
|
|
|
|
|
|
There is one group member for each element in the array ref DEFAULTS. |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
=cut |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
###################################################################### |
1225
|
|
|
|
|
|
|
|
1226
|
0
|
|
|
0
|
1
|
|
sub reset { $_[0]->_proxy( 'reset', \@_ ) } |
1227
|
0
|
|
|
0
|
1
|
|
sub submit { $_[0]->_proxy( 'submit', \@_ ) } |
1228
|
0
|
|
|
0
|
1
|
|
sub hidden { $_[0]->_proxy( 'hidden', \@_ ) } |
1229
|
0
|
|
|
0
|
1
|
|
sub textfield { $_[0]->_proxy( 'textfield', \@_ ) } |
1230
|
0
|
|
|
0
|
1
|
|
sub password_field { $_[0]->_proxy( 'password_field', \@_ ) } |
1231
|
0
|
|
|
0
|
1
|
|
sub textarea { $_[0]->_proxy( 'textarea', \@_ ) } |
1232
|
0
|
|
|
0
|
1
|
|
sub checkbox { $_[0]->_proxy( 'checkbox', \@_ ) } |
1233
|
0
|
|
|
0
|
1
|
|
sub radio { $_[0]->_proxy( 'radio', \@_ ) } |
1234
|
0
|
|
|
0
|
1
|
|
sub popup_menu { $_[0]->_proxy( 'popup_menu', \@_ ) } |
1235
|
0
|
|
|
0
|
1
|
|
sub scrolling_list { $_[0]->_proxy( 'scrolling_list', \@_ ) } |
1236
|
|
|
|
|
|
|
|
1237
|
0
|
|
|
0
|
1
|
|
sub reset_group { $_[0]->_proxy( 'reset_group', \@_ ) } |
1238
|
0
|
|
|
0
|
1
|
|
sub submit_group { $_[0]->_proxy( 'submit_group', \@_ ) } |
1239
|
0
|
|
|
0
|
1
|
|
sub hidden_group { $_[0]->_proxy( 'hidden_group', \@_ ) } |
1240
|
0
|
|
|
0
|
1
|
|
sub textfield_group { $_[0]->_proxy( 'textfield_group', \@_ ) } |
1241
|
0
|
|
|
0
|
1
|
|
sub password_field_group { $_[0]->_proxy( 'password_field_group', \@_ ) } |
1242
|
0
|
|
|
0
|
1
|
|
sub textarea_group { $_[0]->_proxy( 'textarea_group', \@_ ) } |
1243
|
0
|
|
|
0
|
1
|
|
sub checkbox_group { $_[0]->_proxy( 'checkbox_group', \@_ ) } |
1244
|
0
|
|
|
0
|
1
|
|
sub radio_group { $_[0]->_proxy( 'radio_group', \@_ ) } |
1245
|
0
|
|
|
0
|
1
|
|
sub popup_menu_group { $_[0]->_proxy( 'popup_menu_group', \@_ ) } |
1246
|
0
|
|
|
0
|
1
|
|
sub scrolling_list_group { $_[0]->_proxy( 'scrolling_list_group', \@_ ) } |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
###################################################################### |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING TOPS AND BOTTOMS OF HTML FORMS |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
Besides the field-type methods above, these can be used to make pieces of forms |
1253
|
|
|
|
|
|
|
at a time giving you more control of the whole form layout. |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
=head2 start_form([ METHOD[, ACTION] ]) |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
This method returns the top of an HTML form. It consists of the opening 'form' |
1258
|
|
|
|
|
|
|
tag. This method can take its optional two arguments in either named or |
1259
|
|
|
|
|
|
|
positional format; in the first case, the names look the same as the positional |
1260
|
|
|
|
|
|
|
placeholders above, except they must be in lower case. The two arguments, METHOD |
1261
|
|
|
|
|
|
|
and ACTION, are scalars which respectively define the method that the form are |
1262
|
|
|
|
|
|
|
submitted with and the URL it is submitted to. If either argument is undefined, |
1263
|
|
|
|
|
|
|
then the appropriate scalar properties of this object are used instead, and their |
1264
|
|
|
|
|
|
|
defaults are "POST" for METHOD and "127.0.0.1" for ACTION. See the |
1265
|
|
|
|
|
|
|
form_submit_url() and form_submit_method() methods to access these properties. |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
=cut |
1268
|
|
|
|
|
|
|
|
1269
|
|
|
|
|
|
|
###################################################################### |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
sub start_form { |
1272
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1273
|
0
|
|
|
|
|
|
my $rh_params = $self->params_to_hash( \@_, $self->{$KEY_AUTO_POSIT}, |
1274
|
|
|
|
|
|
|
['method', 'action'], undef, undef, 1 ); |
1275
|
0
|
|
0
|
|
|
|
$rh_params->{'method'} ||= $self->{$KEY_SUBMIT_MET}; |
1276
|
0
|
|
0
|
|
|
|
$rh_params->{'action'} ||= $self->{$KEY_SUBMIT_URL}; |
1277
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
1278
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag( 'form', $rh_params, undef, 'start' ) ); |
1279
|
|
|
|
|
|
|
} |
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
###################################################################### |
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
=head2 end_form() |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
This method returns the bottom of an HTML form. It consists of the closing |
1286
|
|
|
|
|
|
|
'form' tag. |
1287
|
|
|
|
|
|
|
|
1288
|
|
|
|
|
|
|
=cut |
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
###################################################################### |
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
sub end_form { |
1293
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1294
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
1295
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag( 'form', {}, undef, 'end' ) ); |
1296
|
|
|
|
|
|
|
} |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
###################################################################### |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
=head2 form_submit_url([ VALUE ]) |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
This method is an accessor for the scalar "submit url" property of this object, |
1303
|
|
|
|
|
|
|
which it returns. If VALUE is defined, this property is set to it. This |
1304
|
|
|
|
|
|
|
property defines the URL of a processing script that the web browser would use to |
1305
|
|
|
|
|
|
|
process the generated form. The default value is "127.0.0.1". |
1306
|
|
|
|
|
|
|
|
1307
|
|
|
|
|
|
|
=cut |
1308
|
|
|
|
|
|
|
|
1309
|
|
|
|
|
|
|
###################################################################### |
1310
|
|
|
|
|
|
|
|
1311
|
|
|
|
|
|
|
sub form_submit_url { |
1312
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1313
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1314
|
0
|
|
|
|
|
|
$self->{$KEY_SUBMIT_URL} = $new_value; |
1315
|
|
|
|
|
|
|
} |
1316
|
0
|
|
|
|
|
|
return( $self->{$KEY_SUBMIT_URL} ); |
1317
|
|
|
|
|
|
|
} |
1318
|
|
|
|
|
|
|
|
1319
|
|
|
|
|
|
|
###################################################################### |
1320
|
|
|
|
|
|
|
|
1321
|
|
|
|
|
|
|
=head2 form_submit_method([ VALUE ]) |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
This method is an accessor for the scalar "submit method" property of this |
1324
|
|
|
|
|
|
|
object, which it returns. If VALUE is defined, this property is set to it. This |
1325
|
|
|
|
|
|
|
property defines the method that the web browser would use to submit form data to |
1326
|
|
|
|
|
|
|
a processor script. The default value is "post", and "get" is the other option. |
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
=cut |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
###################################################################### |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
sub form_submit_method { |
1333
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1334
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1335
|
0
|
|
|
|
|
|
$self->{$KEY_SUBMIT_MET} = $new_value; |
1336
|
|
|
|
|
|
|
} |
1337
|
0
|
|
|
|
|
|
return( $self->{$KEY_SUBMIT_MET} ); |
1338
|
|
|
|
|
|
|
} |
1339
|
|
|
|
|
|
|
|
1340
|
|
|
|
|
|
|
###################################################################### |
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
=head1 METHODS FOR SETTING AND USING STORED FIELD DEFINITIONS |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
=head2 field_definitions([ DEFIN ]) |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
This method is an accessor for the "field definitions" list property of this |
1347
|
|
|
|
|
|
|
object, which it returns. If DEFIN is defined, this property is set to it. This |
1348
|
|
|
|
|
|
|
property is a list of either MultiValuedHash objects or HASH refs, each of which |
1349
|
|
|
|
|
|
|
contains a description for one field or field group that is to be made. Fields |
1350
|
|
|
|
|
|
|
will be processed in the same order they appear in this list. The list is empty |
1351
|
|
|
|
|
|
|
by default. The method also clears any error conditions. |
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
=cut |
1354
|
|
|
|
|
|
|
|
1355
|
|
|
|
|
|
|
###################################################################### |
1356
|
|
|
|
|
|
|
|
1357
|
|
|
|
|
|
|
sub field_definitions { |
1358
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1359
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1360
|
0
|
0
|
|
|
|
|
my @fields = ref($new_value) eq 'ARRAY' ? @{$new_value} : $new_value; |
|
0
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
|
|
1362
|
0
|
|
|
|
|
|
my @field_defn = (); |
1363
|
|
|
|
|
|
|
|
1364
|
0
|
|
|
|
|
|
foreach my $defin (@fields) { |
1365
|
0
|
0
|
|
|
|
|
if( UNIVERSAL::isa( $defin, 'Data::MultiValuedHash' ) ) { |
1366
|
0
|
|
|
|
|
|
$defin = $defin->fetch_all(); |
1367
|
|
|
|
|
|
|
} |
1368
|
0
|
0
|
|
|
|
|
ref( $defin ) eq 'HASH' or next; # improper input so we skip |
1369
|
0
|
|
|
|
|
|
$defin = $self->_rename_defin_props( $defin ); |
1370
|
0
|
|
|
|
|
|
$defin = Data::MultiValuedHash->new( 1, $defin ); # copy input |
1371
|
0
|
|
|
|
|
|
push( @field_defn, $defin ); |
1372
|
|
|
|
|
|
|
} |
1373
|
|
|
|
|
|
|
|
1374
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_DEFNA} = \@field_defn; |
1375
|
0
|
|
|
|
|
|
$self->{$KEY_NORMALIZED} = 0; |
1376
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = undef; |
1377
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = undef; |
1378
|
|
|
|
|
|
|
} |
1379
|
0
|
|
|
|
|
|
return( [@{$self->{$KEY_FIELD_DEFNA}}] ); # refs to indiv defins returned |
|
0
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
} |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
###################################################################### |
1383
|
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
=head2 fields_normalized() |
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
This method returns true if the field definitions have been "normalized". The |
1387
|
|
|
|
|
|
|
boolean property that tracks this condition is false by default and only becomes |
1388
|
|
|
|
|
|
|
true when normalize_field_definitions() is called. It becomes false when |
1389
|
|
|
|
|
|
|
field_definitions() is called. |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
=cut |
1392
|
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
|
###################################################################### |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
sub fields_normalized { |
1396
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1397
|
0
|
|
|
|
|
|
return( $self->{$KEY_NORMALIZED} ) |
1398
|
|
|
|
|
|
|
} |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
###################################################################### |
1401
|
|
|
|
|
|
|
|
1402
|
|
|
|
|
|
|
=head2 normalize_field_definitions() |
1403
|
|
|
|
|
|
|
|
1404
|
|
|
|
|
|
|
This method edits the "field definitions" such that any fields without names are |
1405
|
|
|
|
|
|
|
given one (called "nonamefieldNNN"), any unknown field types become textfields, |
1406
|
|
|
|
|
|
|
and any special fields we use internally are created. It returns true when |
1407
|
|
|
|
|
|
|
finished. This method is called by any input checking or html making routines if |
1408
|
|
|
|
|
|
|
"normalized" is false because it is a precondition for them to work properly. |
1409
|
|
|
|
|
|
|
|
1410
|
|
|
|
|
|
|
=cut |
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
###################################################################### |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
sub normalize_field_definitions { |
1415
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1416
|
0
|
|
|
|
|
|
my $ra_field_defn = $self->{$KEY_FIELD_DEFNA}; |
1417
|
|
|
|
|
|
|
|
1418
|
0
|
|
|
|
|
|
my $nfn_field_count = 0; |
1419
|
0
|
|
|
|
|
|
my $has_is_submit = 0; |
1420
|
0
|
|
|
|
|
|
my $has_submit_button = 0; |
1421
|
|
|
|
|
|
|
|
1422
|
0
|
|
|
|
|
|
foreach my $defin (@{$ra_field_defn}) { |
|
0
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
|
1424
|
|
|
|
|
|
|
# Make sure the field definition has a valid field type. |
1425
|
|
|
|
|
|
|
|
1426
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
1427
|
0
|
0
|
|
|
|
|
unless( $FIELD_TYPES{$type} ) { |
1428
|
0
|
|
|
|
|
|
$type = $self->{$KEY_DEF_FF_TYPE}; |
1429
|
0
|
|
|
|
|
|
$defin->store( $FKEY_TYPE, $type ); |
1430
|
|
|
|
|
|
|
} |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
# Make sure the field definition has field name. |
1433
|
|
|
|
|
|
|
|
1434
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1435
|
0
|
0
|
0
|
|
|
|
if( !$name or $name =~ /^$self->{$KEY_DEF_FF_NAME}/ ) { |
1436
|
0
|
|
|
|
|
|
$name = $self->{$KEY_DEF_FF_NAME}. |
1437
|
|
|
|
|
|
|
sprintf( "%3.3d", ++$nfn_field_count ); |
1438
|
0
|
|
|
|
|
|
$defin->store( $FKEY_NAME, $name ); |
1439
|
|
|
|
|
|
|
} |
1440
|
|
|
|
|
|
|
|
1441
|
0
|
0
|
|
|
|
|
$name eq $self->{$KEY_IS_SUBMIT} and $has_is_submit = 1; |
1442
|
0
|
0
|
|
|
|
|
$type eq 'submit' and $has_submit_button = 1; |
1443
|
|
|
|
|
|
|
} |
1444
|
|
|
|
|
|
|
|
1445
|
0
|
0
|
|
|
|
|
unless( $has_is_submit ) { |
1446
|
0
|
|
|
|
|
|
unshift( @{$ra_field_defn}, Data::MultiValuedHash->new( 1, { |
|
0
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
$FKEY_TYPE => 'hidden', |
1448
|
|
|
|
|
|
|
$FKEY_NAME => $self->{$KEY_IS_SUBMIT}, |
1449
|
|
|
|
|
|
|
$FKEY_DEFAULTS => 1, |
1450
|
|
|
|
|
|
|
} ) ); |
1451
|
|
|
|
|
|
|
} |
1452
|
|
|
|
|
|
|
|
1453
|
0
|
0
|
|
|
|
|
unless( $has_submit_button ) { |
1454
|
0
|
|
|
|
|
|
push( @{$ra_field_defn}, Data::MultiValuedHash->new( 1, { |
|
0
|
|
|
|
|
|
|
1455
|
|
|
|
|
|
|
$FKEY_TYPE => 'submit', |
1456
|
|
|
|
|
|
|
$FKEY_NAME => $self->{$KEY_DEF_FF_NAME}. |
1457
|
|
|
|
|
|
|
sprintf( "%3.3d", ++$nfn_field_count ), |
1458
|
|
|
|
|
|
|
} ) ); |
1459
|
|
|
|
|
|
|
} |
1460
|
|
|
|
|
|
|
|
1461
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = undef; |
1462
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = undef; |
1463
|
0
|
|
|
|
|
|
return( $self->{$KEY_NORMALIZED} = 1 ); |
1464
|
|
|
|
|
|
|
} |
1465
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
###################################################################### |
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING FIELD HTML USING STORED DEFINITIONS |
1469
|
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
|
=head2 field_html([ NAME ]) |
1471
|
|
|
|
|
|
|
|
1472
|
|
|
|
|
|
|
This method returns generated html code for form fields that were defined using |
1473
|
|
|
|
|
|
|
field_definitions(). If NAME is defined it only returnes code for the field (or |
1474
|
|
|
|
|
|
|
group) with that name; otherwise it returns a list of html for all fields. This |
1475
|
|
|
|
|
|
|
is useful if you want to define your form fields ahead of time, but still want to |
1476
|
|
|
|
|
|
|
roll your own complete form. |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
=cut |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
###################################################################### |
1481
|
|
|
|
|
|
|
|
1482
|
|
|
|
|
|
|
sub field_html { |
1483
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
1484
|
0
|
0
|
|
|
|
|
unless( defined( $self->{$KEY_FIELD_RENDE} ) ) { |
1485
|
0
|
|
|
|
|
|
$self->make_field_html(); |
1486
|
|
|
|
|
|
|
} |
1487
|
0
|
0
|
|
|
|
|
if( defined( $name ) ) { |
1488
|
0
|
|
|
|
|
|
return( $self->{$KEY_FIELD_RENDE}->{$name} ); |
1489
|
|
|
|
|
|
|
} else { |
1490
|
0
|
|
|
|
|
|
return( {%{$self->{$KEY_FIELD_RENDE}}} ); |
|
0
|
|
|
|
|
|
|
1491
|
|
|
|
|
|
|
} |
1492
|
|
|
|
|
|
|
} |
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
###################################################################### |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
=head2 make_field_html() |
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
This method goes through all the fields and has html made for them, then puts it |
1499
|
|
|
|
|
|
|
away for those that need it, namely make_html_input_form() and field_html(). It |
1500
|
|
|
|
|
|
|
returns a count of the number of fields generated, which includes all hidden |
1501
|
|
|
|
|
|
|
fields and buttons. |
1502
|
|
|
|
|
|
|
|
1503
|
|
|
|
|
|
|
=cut |
1504
|
|
|
|
|
|
|
|
1505
|
|
|
|
|
|
|
###################################################################### |
1506
|
|
|
|
|
|
|
|
1507
|
|
|
|
|
|
|
sub make_field_html { |
1508
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1509
|
0
|
0
|
|
|
|
|
$self->{$KEY_NORMALIZED} or $self->normalize_field_definitions(); |
1510
|
0
|
|
|
|
|
|
my %field_html = (); |
1511
|
0
|
|
|
|
|
|
foreach my $defin (@{$self->{$KEY_FIELD_DEFNA}}) { |
|
0
|
|
|
|
|
|
|
1512
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1513
|
0
|
|
|
|
|
|
$field_html{$name} = $self->_make_field_html( $defin ); |
1514
|
|
|
|
|
|
|
} |
1515
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} = \%field_html; |
1516
|
0
|
|
|
|
|
|
return( scalar( keys %field_html ) ); |
1517
|
|
|
|
|
|
|
} |
1518
|
|
|
|
|
|
|
|
1519
|
|
|
|
|
|
|
###################################################################### |
1520
|
|
|
|
|
|
|
|
1521
|
|
|
|
|
|
|
=head1 METHODS FOR USER INPUT VALIDATION USING STORED DEFINITIONS |
1522
|
|
|
|
|
|
|
|
1523
|
|
|
|
|
|
|
=head2 invalid_input([ NAMES ]) |
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
This method is an accessor for the "invalid input" property of this object, which |
1526
|
|
|
|
|
|
|
it returns. If NAMES is a valid hash ref, this property is set to it. This |
1527
|
|
|
|
|
|
|
property is a hash that indicates which fields have invalid input. The property |
1528
|
|
|
|
|
|
|
is undefined by default, and is set when validate_form_input() is called. The |
1529
|
|
|
|
|
|
|
optional NAMES argument lets you override the internal input checking to apply |
1530
|
|
|
|
|
|
|
your own input checking. If you want both to happen, then call it once with no |
1531
|
|
|
|
|
|
|
arguments (internal is automatically done), then edit the results, then call this |
1532
|
|
|
|
|
|
|
again providing your new hash as an argument. |
1533
|
|
|
|
|
|
|
|
1534
|
|
|
|
|
|
|
=cut |
1535
|
|
|
|
|
|
|
|
1536
|
|
|
|
|
|
|
###################################################################### |
1537
|
|
|
|
|
|
|
|
1538
|
|
|
|
|
|
|
sub invalid_input { |
1539
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1540
|
0
|
0
|
|
|
|
|
if( ref( $new_value ) eq 'HASH' ) { |
1541
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = {%{$new_value}}; |
|
0
|
|
|
|
|
|
|
1542
|
|
|
|
|
|
|
} |
1543
|
0
|
0
|
|
|
|
|
unless( defined( $self->{$KEY_FIELD_INVAL} ) ) { |
1544
|
0
|
|
|
|
|
|
$self->validate_form_input(); |
1545
|
|
|
|
|
|
|
} |
1546
|
0
|
|
|
|
|
|
return( $self->{$KEY_FIELD_INVAL} ); # returns ref; caller may change |
1547
|
|
|
|
|
|
|
} |
1548
|
|
|
|
|
|
|
|
1549
|
|
|
|
|
|
|
###################################################################### |
1550
|
|
|
|
|
|
|
|
1551
|
|
|
|
|
|
|
=head2 validate_form_input() |
1552
|
|
|
|
|
|
|
|
1553
|
|
|
|
|
|
|
This method sets the "invalid input" property by applying the various input |
1554
|
|
|
|
|
|
|
checking properties of the fields to the user input for those fields. If "new |
1555
|
|
|
|
|
|
|
form" is true then all fields are declared to be error free. It returns a count |
1556
|
|
|
|
|
|
|
of the number of erroneous fields, and 0 if there are no errors. This method is |
1557
|
|
|
|
|
|
|
called by make_html_input_form() and invalid_input() if "invalid input" is false |
1558
|
|
|
|
|
|
|
because it is a precondition for them to work properly. If the "validation rule" |
1559
|
|
|
|
|
|
|
regular expression does not compile, then Perl automatically throws an exception. |
1560
|
|
|
|
|
|
|
|
1561
|
|
|
|
|
|
|
=cut |
1562
|
|
|
|
|
|
|
|
1563
|
|
|
|
|
|
|
###################################################################### |
1564
|
|
|
|
|
|
|
|
1565
|
|
|
|
|
|
|
sub validate_form_input { |
1566
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
1567
|
0
|
0
|
|
|
|
|
$self->{$KEY_NORMALIZED} or $self->normalize_field_definitions(); |
1568
|
|
|
|
|
|
|
|
1569
|
0
|
0
|
|
|
|
|
if( $self->{$KEY_NEW_FORM} ) { |
1570
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = {}; |
1571
|
0
|
|
|
|
|
|
return( 0 ); |
1572
|
|
|
|
|
|
|
} |
1573
|
|
|
|
|
|
|
|
1574
|
0
|
|
|
|
|
|
my $user_input = $self->{$KEY_FIELD_INPUT}; |
1575
|
0
|
|
|
|
|
|
my %input_invalid = (); |
1576
|
|
|
|
|
|
|
|
1577
|
0
|
|
|
|
|
|
foreach my $defin (@{$self->{$KEY_FIELD_DEFNA}}) { |
|
0
|
|
|
|
|
|
|
1578
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
1579
|
|
|
|
|
|
|
|
1580
|
|
|
|
|
|
|
# Don't check hidden fields or buttons since user can't change them. |
1581
|
|
|
|
|
|
|
|
1582
|
0
|
0
|
|
|
|
|
next unless( $FIELD_TYPES{$type}->{$TKEY_EDITAB} ); |
1583
|
|
|
|
|
|
|
|
1584
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1585
|
0
|
|
|
|
|
|
my $is_required = $defin->fetch_value( $FKEY_IS_REQUIRED ); |
1586
|
0
|
|
|
|
|
|
my $min_count = $defin->fetch_value( $FKEY_REQ_MIN_COUNT ); |
1587
|
0
|
|
|
|
|
|
my $max_count = $defin->fetch_value( $FKEY_REQ_MAX_COUNT ); |
1588
|
0
|
|
|
|
|
|
my $req_options = $defin->fetch_value( $FKEY_REQ_OPT_MATCH ); |
1589
|
0
|
|
|
|
|
|
my $pattern = $defin->fetch_value( $FKEY_VALIDATION_RULE ); |
1590
|
|
|
|
|
|
|
|
1591
|
|
|
|
|
|
|
# Fetch any input that exists; filter out empty strings. |
1592
|
|
|
|
|
|
|
|
1593
|
0
|
|
|
|
|
|
my @input = grep { $_ ne '' } $user_input->fetch( $name ); |
|
0
|
|
|
|
|
|
|
1594
|
0
|
|
|
|
|
|
my $input_count = @input; |
1595
|
|
|
|
|
|
|
|
1596
|
|
|
|
|
|
|
# If input is required then empty fields are an error. |
1597
|
|
|
|
|
|
|
|
1598
|
0
|
0
|
|
|
|
|
if( $is_required ) { |
1599
|
0
|
0
|
|
|
|
|
unless( $input_count ) { |
1600
|
0
|
|
|
|
|
|
$input_invalid{$name} = $FKEY_IS_REQUIRED; |
1601
|
0
|
|
|
|
|
|
next; |
1602
|
|
|
|
|
|
|
} |
1603
|
|
|
|
|
|
|
} |
1604
|
|
|
|
|
|
|
|
1605
|
|
|
|
|
|
|
# If at least MIN values must be entered/selected, less is an error. |
1606
|
|
|
|
|
|
|
|
1607
|
0
|
0
|
|
|
|
|
if( defined( $min_count ) ) { |
1608
|
0
|
0
|
|
|
|
|
unless( $input_count >= $min_count ) { |
1609
|
0
|
|
|
|
|
|
$input_invalid{$name} = $FKEY_REQ_MIN_COUNT; |
1610
|
0
|
|
|
|
|
|
next; |
1611
|
|
|
|
|
|
|
} |
1612
|
|
|
|
|
|
|
} |
1613
|
|
|
|
|
|
|
|
1614
|
|
|
|
|
|
|
# If at most MAX values must be entered/selected, more is an error. |
1615
|
|
|
|
|
|
|
|
1616
|
0
|
0
|
|
|
|
|
if( defined( $max_count ) ) { |
1617
|
0
|
0
|
|
|
|
|
unless( $input_count <= $max_count ) { |
1618
|
0
|
|
|
|
|
|
$input_invalid{$name} = $FKEY_REQ_MAX_COUNT; |
1619
|
0
|
|
|
|
|
|
next; |
1620
|
|
|
|
|
|
|
} |
1621
|
|
|
|
|
|
|
} |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
# If this is a selection field, then verify that the user input matches |
1624
|
|
|
|
|
|
|
# available selections for that field. The @matched array below is the |
1625
|
|
|
|
|
|
|
# intersection of VALUES and INPUT sets. |
1626
|
|
|
|
|
|
|
|
1627
|
0
|
0
|
0
|
|
|
|
if( $req_options and $FIELD_TYPES{$type}->{$TKEY_SELECT} ) { |
1628
|
0
|
|
|
|
|
|
my %values = map { ( $_ => 1 ) } $defin->fetch( $FKEY_VALUES ); |
|
0
|
|
|
|
|
|
|
1629
|
0
|
|
|
|
|
|
my @matched = grep { $values{$_} } @input; |
|
0
|
|
|
|
|
|
|
1630
|
0
|
0
|
|
|
|
|
unless( $input_count == scalar( @matched ) ) { |
1631
|
0
|
|
|
|
|
|
$input_invalid{$name} = $FKEY_REQ_OPT_MATCH; |
1632
|
0
|
|
|
|
|
|
next; |
1633
|
|
|
|
|
|
|
} |
1634
|
|
|
|
|
|
|
} |
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
# Optionally do a simple pattern-match for valid input. |
1637
|
|
|
|
|
|
|
|
1638
|
0
|
0
|
|
|
|
|
if( defined( $pattern ) ) { |
1639
|
0
|
|
|
|
|
|
my @matched = grep { $_ =~ /$pattern/ } @input; |
|
0
|
|
|
|
|
|
|
1640
|
0
|
0
|
|
|
|
|
unless( $input_count == scalar( @matched ) ) { |
1641
|
0
|
|
|
|
|
|
$input_invalid{$name} = $FKEY_VALIDATION_RULE; |
1642
|
0
|
|
|
|
|
|
next; |
1643
|
|
|
|
|
|
|
} |
1644
|
|
|
|
|
|
|
} |
1645
|
|
|
|
|
|
|
} |
1646
|
|
|
|
|
|
|
|
1647
|
0
|
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} = \%input_invalid; |
1648
|
0
|
|
|
|
|
|
return( scalar( keys %input_invalid ) ); |
1649
|
|
|
|
|
|
|
} |
1650
|
|
|
|
|
|
|
|
1651
|
|
|
|
|
|
|
###################################################################### |
1652
|
|
|
|
|
|
|
|
1653
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING WHOLE FORMS AT ONCE |
1654
|
|
|
|
|
|
|
|
1655
|
|
|
|
|
|
|
=head2 make_html_input_form([ TABLE[, LIST] ]) |
1656
|
|
|
|
|
|
|
|
1657
|
|
|
|
|
|
|
This method returns a complete html input form, including all form field tags, |
1658
|
|
|
|
|
|
|
reflected user input values, various text headings and labels, and any visual |
1659
|
|
|
|
|
|
|
cues indicating special status for various fields. The first optional boolean |
1660
|
|
|
|
|
|
|
argument, TABLE, says to return the form within an HTML table, with one field or |
1661
|
|
|
|
|
|
|
field group per row. Field headings and help text appear on the left and the |
1662
|
|
|
|
|
|
|
field or group itself appears on the right. All table cells are |
1663
|
|
|
|
|
|
|
top-left-aligned, and no widths or heights are specified. If TABLE is false then |
1664
|
|
|
|
|
|
|
each field or group is returned in a paragraph that starts with its title. The |
1665
|
|
|
|
|
|
|
second optional boolean argument, LIST, causes the resulting form body to be |
1666
|
|
|
|
|
|
|
returned as an array ref whose elements are pieces of the page. If this is false |
1667
|
|
|
|
|
|
|
then everything is returned in a single scalar. |
1668
|
|
|
|
|
|
|
|
1669
|
|
|
|
|
|
|
=cut |
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
###################################################################### |
1672
|
|
|
|
|
|
|
|
1673
|
|
|
|
|
|
|
sub make_html_input_form { |
1674
|
0
|
|
|
0
|
1
|
|
my ($self, $in_table_format, $force_list ) = @_; |
1675
|
0
|
0
|
|
|
|
|
$self->{$KEY_FIELD_RENDE} or $self->make_field_html(); |
1676
|
0
|
0
|
|
|
|
|
$self->{$KEY_FIELD_INVAL} or $self->validate_form_input(); |
1677
|
|
|
|
|
|
|
|
1678
|
0
|
|
|
|
|
|
my $rh_field_html = $self->{$KEY_FIELD_RENDE}; |
1679
|
0
|
|
|
|
|
|
my $rh_invalid = $self->{$KEY_FIELD_INVAL}; |
1680
|
0
|
|
|
|
|
|
my @input_form = (); |
1681
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
1682
|
|
|
|
|
|
|
|
1683
|
0
|
|
|
|
|
|
push( @input_form, $self->start_form() ); |
1684
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1685
|
0
|
|
|
|
|
|
push( @input_form, "\n" );
1686
|
|
|
|
|
|
|
} |
1687
|
|
|
|
|
|
|
|
1688
|
0
|
|
|
|
|
|
foreach my $defin (@{$self->{$KEY_FIELD_DEFNA}}) { |
|
0
|
|
|
|
|
|
|
1689
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
1690
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1691
|
|
|
|
|
|
|
|
1692
|
0
|
0
|
|
|
|
|
unless( $FIELD_TYPES{$type}->{$TKEY_VISIBL} ) { |
1693
|
0
|
|
|
|
|
|
push( @input_form, $rh_field_html->{$name} ); |
1694
|
0
|
|
|
|
|
|
next; |
1695
|
|
|
|
|
|
|
} |
1696
|
|
|
|
|
|
|
|
1697
|
0
|
|
|
|
|
|
my $flags_html = ''; |
1698
|
0
|
|
|
|
|
|
my $label_html = ''; |
1699
|
0
|
|
|
|
|
|
my $error_html = ''; |
1700
|
|
|
|
|
|
|
|
1701
|
0
|
0
|
|
|
|
|
if( $FIELD_TYPES{$type}->{$TKEY_EDITAB} ) { |
1702
|
0
|
0
|
|
|
|
|
if( $rh_invalid->{$name} ) { |
1703
|
0
|
|
|
|
|
|
$flags_html .= "\n$self->{$KEY_INVAL_MARK}"; |
1704
|
|
|
|
|
|
|
} |
1705
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_IS_REQUIRED ) ) { |
1706
|
0
|
|
|
|
|
|
$flags_html .= "\n$self->{$KEY_ISREQ_MARK}"; |
1707
|
|
|
|
|
|
|
} |
1708
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_IS_PRIVATE ) ) { |
1709
|
0
|
|
|
|
|
|
$flags_html .= "\n$self->{$KEY_PRIVA_MARK}"; |
1710
|
|
|
|
|
|
|
} |
1711
|
|
|
|
|
|
|
|
1712
|
0
|
|
|
|
|
|
$label_html .= "\n" . |
1713
|
|
|
|
|
|
|
$defin->fetch_value( $FKEY_VISIBLE_TITLE ) . ":"; |
1714
|
0
|
0
|
|
|
|
|
if( my $hm = $defin->fetch_value( $FKEY_HELP_MESSAGE ) ) { |
1715
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1716
|
0
|
|
|
|
|
|
$label_html .= " "; |
1717
|
|
|
|
|
|
|
} |
1718
|
0
|
|
|
|
|
|
$label_html .= "\n($hm)"; |
1719
|
|
|
|
|
|
|
} |
1720
|
|
|
|
|
|
|
|
1721
|
0
|
0
|
|
|
|
|
if( $rh_invalid->{$name} ) { |
1722
|
0
|
|
|
|
|
|
$error_html .= "\n" . |
1723
|
|
|
|
|
|
|
$defin->fetch_value( $FKEY_ERROR_MESSAGE ) . |
1724
|
|
|
|
|
|
|
""; |
1725
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1726
|
0
|
|
|
|
|
|
$error_html .= " "; |
1727
|
|
|
|
|
|
|
} |
1728
|
|
|
|
|
|
|
} |
1729
|
|
|
|
|
|
|
} |
1730
|
|
|
|
|
|
|
|
1731
|
0
|
|
|
|
|
|
my $field_html = $rh_field_html->{$name}; |
1732
|
0
|
|
|
|
|
|
ref( $field_html ) eq 'ARRAY' and |
1733
|
0
|
0
|
|
|
|
|
$field_html = join( '', @{$field_html} ); # compensate "list" attr |
1734
|
0
|
|
|
|
|
|
my $str_above = $defin->fetch_value( $FKEY_STR_ABOVE_INPUT ); |
1735
|
0
|
|
|
|
|
|
my $str_below = $defin->fetch_value( $FKEY_STR_BELOW_INPUT ); |
1736
|
|
|
|
|
|
|
|
1737
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1738
|
0
|
|
|
|
|
|
push( @input_form, <<__endquote ); |
1739
|
|
|
|
|
|
|
\n |
1740
|
|
|
|
|
|
|
| $flags_html |
1741
|
|
|
|
|
|
|
| $label_html |
1742
|
|
|
|
|
|
|
| $error_html$str_above$field_html$str_below |
1743
|
|
|
|
|
|
|
__endquote |
1744
|
|
|
|
|
|
|
} else { |
1745
|
0
|
|
|
|
|
|
push( @input_form, <<__endquote ); |
1746
|
|
|
|
|
|
|
\n |
1747
|
|
|
|
|
|
|
$flags_html |
1748
|
|
|
|
|
|
|
$label_html |
1749
|
|
|
|
|
|
|
$error_html$str_above$field_html$str_below |
1750
|
|
|
|
|
|
|
__endquote |
1751
|
|
|
|
|
|
|
} |
1752
|
|
|
|
|
|
|
} |
1753
|
|
|
|
|
|
|
|
1754
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1755
|
0
|
|
|
|
|
|
push( @input_form, "\n | " ); |
1756
|
|
|
|
|
|
|
} |
1757
|
0
|
|
|
|
|
|
push( @input_form, $self->end_form() ); |
1758
|
|
|
|
|
|
|
|
1759
|
0
|
0
|
|
|
|
|
return( $force_list ? \@input_form : join( '', @input_form ) ); |
1760
|
|
|
|
|
|
|
} |
1761
|
|
|
|
|
|
|
|
1762
|
|
|
|
|
|
|
###################################################################### |
1763
|
|
|
|
|
|
|
|
1764
|
|
|
|
|
|
|
=head2 bad_input_marker([ VALUE ]) |
1765
|
|
|
|
|
|
|
|
1766
|
|
|
|
|
|
|
This method is an accessor for the string "invalid input marker" property of |
1767
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
1768
|
|
|
|
|
|
|
This string is used to visually indicate in which form fields the user has |
1769
|
|
|
|
|
|
|
entered invalid input. It defaults to a question mark ("?"). |
1770
|
|
|
|
|
|
|
|
1771
|
|
|
|
|
|
|
=cut |
1772
|
|
|
|
|
|
|
|
1773
|
|
|
|
|
|
|
###################################################################### |
1774
|
|
|
|
|
|
|
|
1775
|
|
|
|
|
|
|
sub bad_input_marker { |
1776
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1777
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1778
|
0
|
|
|
|
|
|
$self->{$KEY_INVAL_MARK} = $new_value; |
1779
|
|
|
|
|
|
|
} |
1780
|
0
|
|
|
|
|
|
return( $self->{$KEY_INVAL_MARK} ); |
1781
|
|
|
|
|
|
|
} |
1782
|
|
|
|
|
|
|
|
1783
|
|
|
|
|
|
|
###################################################################### |
1784
|
|
|
|
|
|
|
|
1785
|
|
|
|
|
|
|
=head2 required_field_marker([ VALUE ]) |
1786
|
|
|
|
|
|
|
|
1787
|
|
|
|
|
|
|
This method is an accessor for the string "required field marker" property of |
1788
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
1789
|
|
|
|
|
|
|
This string is used to visually indicate which form fields are required, and |
1790
|
|
|
|
|
|
|
must be filled in by users for the form to be processed. It defaults to |
1791
|
|
|
|
|
|
|
an asterisk ("*"). |
1792
|
|
|
|
|
|
|
|
1793
|
|
|
|
|
|
|
=cut |
1794
|
|
|
|
|
|
|
|
1795
|
|
|
|
|
|
|
###################################################################### |
1796
|
|
|
|
|
|
|
|
1797
|
|
|
|
|
|
|
sub required_field_marker { |
1798
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1799
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1800
|
0
|
|
|
|
|
|
$self->{$KEY_ISREQ_MARK} = $new_value; |
1801
|
|
|
|
|
|
|
} |
1802
|
0
|
|
|
|
|
|
return( $self->{$KEY_ISREQ_MARK} ); |
1803
|
|
|
|
|
|
|
} |
1804
|
|
|
|
|
|
|
|
1805
|
|
|
|
|
|
|
###################################################################### |
1806
|
|
|
|
|
|
|
|
1807
|
|
|
|
|
|
|
=head2 private_field_marker([ VALUE ]) |
1808
|
|
|
|
|
|
|
|
1809
|
|
|
|
|
|
|
This method is an accessor for the string "private field marker" property of |
1810
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
1811
|
|
|
|
|
|
|
This string is used to visually indicate which form fields are meant to be |
1812
|
|
|
|
|
|
|
private, meaning their content won't be shown to the public. It defaults to |
1813
|
|
|
|
|
|
|
a tilde ("~"). |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
=cut |
1816
|
|
|
|
|
|
|
|
1817
|
|
|
|
|
|
|
###################################################################### |
1818
|
|
|
|
|
|
|
|
1819
|
|
|
|
|
|
|
sub private_field_marker { |
1820
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1821
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1822
|
0
|
|
|
|
|
|
$self->{$KEY_PRIVA_MARK} = $new_value; |
1823
|
|
|
|
|
|
|
} |
1824
|
0
|
|
|
|
|
|
return( $self->{$KEY_PRIVA_MARK} ); |
1825
|
|
|
|
|
|
|
} |
1826
|
|
|
|
|
|
|
|
1827
|
|
|
|
|
|
|
###################################################################### |
1828
|
|
|
|
|
|
|
|
1829
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING WHOLE REPORTS AT ONCE |
1830
|
|
|
|
|
|
|
|
1831
|
|
|
|
|
|
|
=head2 make_html_input_echo([ TABLE[, EXCLUDE[, EMPTY[, LIST]]] ]) |
1832
|
|
|
|
|
|
|
|
1833
|
|
|
|
|
|
|
This method returns a complete html-formatted input "echo" report that includes |
1834
|
|
|
|
|
|
|
all the field titles and reflected user input values. Any buttons or hidden |
1835
|
|
|
|
|
|
|
fields are excluded. There is nothing that indicates whether the user input has |
1836
|
|
|
|
|
|
|
errors or not. There is one heading per field group, and the values from each |
1837
|
|
|
|
|
|
|
member of the group are displayed together in a list. The first optional boolean |
1838
|
|
|
|
|
|
|
argument, TABLE, says to return the report within an HTML table, with one field |
1839
|
|
|
|
|
|
|
or field group per row. All table cells are top-left-aligned, and no widths or |
1840
|
|
|
|
|
|
|
heights are specified. If TABLE is false then each field or group input is |
1841
|
|
|
|
|
|
|
returned in a paragraph that starts with its title. The second optional boolean |
1842
|
|
|
|
|
|
|
argument, EXCLUDE, ensures that any fields that were defined to be "private" are |
1843
|
|
|
|
|
|
|
excluded from this report; by default they are included. The third optional |
1844
|
|
|
|
|
|
|
string argument, EMPTY, specifies the string to use in place of the user's input |
1845
|
|
|
|
|
|
|
where the user left the field empty; by default nothing is shown. The fourth |
1846
|
|
|
|
|
|
|
optional boolean argument, LIST, causes the resulting form body to be returned |
1847
|
|
|
|
|
|
|
as an array ref whose elements are pieces of the page. If this is false then |
1848
|
|
|
|
|
|
|
everything is returned in a single scalar. |
1849
|
|
|
|
|
|
|
|
1850
|
|
|
|
|
|
|
=cut |
1851
|
|
|
|
|
|
|
|
1852
|
|
|
|
|
|
|
###################################################################### |
1853
|
|
|
|
|
|
|
|
1854
|
|
|
|
|
|
|
sub make_html_input_echo { |
1855
|
0
|
|
|
0
|
1
|
|
my ($self, $in_table_format, $exclude_private, $empty_field_str, |
1856
|
|
|
|
|
|
|
$force_list) = @_; |
1857
|
0
|
0
|
|
|
|
|
defined( $empty_field_str ) or $empty_field_str = $self->{$KEY_EMP_ECH_STR}; |
1858
|
0
|
0
|
|
|
|
|
$self->{$KEY_NORMALIZED} or $self->normalize_field_definitions(); |
1859
|
|
|
|
|
|
|
|
1860
|
0
|
|
|
|
|
|
my $user_input = $self->{$KEY_FIELD_INPUT}; |
1861
|
0
|
|
|
|
|
|
my @input_echo = (); |
1862
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
1863
|
|
|
|
|
|
|
|
1864
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1865
|
0
|
|
|
|
|
|
push( @input_echo, "\n" );
1866
|
|
|
|
|
|
|
} |
1867
|
|
|
|
|
|
|
|
1868
|
0
|
|
|
|
|
|
foreach my $defin (@{$self->{$KEY_FIELD_DEFNA}}) { |
|
0
|
|
|
|
|
|
|
1869
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
1870
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1871
|
|
|
|
|
|
|
|
1872
|
0
|
0
|
|
|
|
|
unless( $FIELD_TYPES{$type}->{$TKEY_EDITAB} ) { |
1873
|
0
|
|
|
|
|
|
next; |
1874
|
|
|
|
|
|
|
} |
1875
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_EXCLUDE_IN_ECHO ) ) { |
1876
|
0
|
|
|
|
|
|
next; |
1877
|
|
|
|
|
|
|
} |
1878
|
0
|
0
|
0
|
|
|
|
if( $exclude_private and $defin->fetch_value( $FKEY_IS_PRIVATE ) ) { |
1879
|
0
|
|
|
|
|
|
next; |
1880
|
|
|
|
|
|
|
} |
1881
|
|
|
|
|
|
|
|
1882
|
0
|
|
|
|
|
|
my $field_title = "\n" . |
1883
|
|
|
|
|
|
|
$defin->fetch_value( $FKEY_VISIBLE_TITLE ) . ":"; |
1884
|
|
|
|
|
|
|
|
1885
|
0
|
|
|
|
|
|
my @input = grep { $_ ne '' } $user_input->fetch( $name ); |
|
0
|
|
|
|
|
|
|
1886
|
0
|
0
|
|
|
|
|
scalar( @input ) or @input = $empty_field_str; |
1887
|
0
|
|
|
|
|
|
foreach (@input) { |
1888
|
0
|
|
|
|
|
|
s/&/&/g; |
1889
|
0
|
|
|
|
|
|
s/\"/"/g; |
1890
|
0
|
|
|
|
|
|
s/>/>/g; |
1891
|
0
|
|
|
|
|
|
s/</g; |
1892
|
|
|
|
|
|
|
} |
1893
|
0
|
0
|
|
|
|
|
my $user_input_str = join( $in_table_format ? ' ' : ', ', @input ); |
1894
|
|
|
|
|
|
|
|
1895
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1896
|
0
|
|
|
|
|
|
push( @input_echo, |
1897
|
|
|
|
|
|
|
"\n | $field_title | $user_input_str | " );
1898
|
|
|
|
|
|
|
} else { |
1899
|
0
|
|
|
|
|
|
push( @input_echo, "\n $field_title $user_input_str " ); |
1900
|
|
|
|
|
|
|
} |
1901
|
|
|
|
|
|
|
} |
1902
|
|
|
|
|
|
|
|
1903
|
0
|
0
|
|
|
|
|
if( $in_table_format ) { |
1904
|
0
|
|
|
|
|
|
push( @input_echo, "\n | " ); |
1905
|
|
|
|
|
|
|
} |
1906
|
|
|
|
|
|
|
|
1907
|
0
|
0
|
|
|
|
|
return( $force_list ? \@input_echo : join( '', @input_echo ) ); |
1908
|
|
|
|
|
|
|
} |
1909
|
|
|
|
|
|
|
|
1910
|
|
|
|
|
|
|
###################################################################### |
1911
|
|
|
|
|
|
|
|
1912
|
|
|
|
|
|
|
=head2 make_text_input_echo([ EXCLUDE[, EMPTY[, LIST]] ]) |
1913
|
|
|
|
|
|
|
|
1914
|
|
|
|
|
|
|
This method returns a complete plain-text-formatted input "echo" report that |
1915
|
|
|
|
|
|
|
includes all the field titles and reflected user input values. This report is |
1916
|
|
|
|
|
|
|
designed not for web display but for text reports or for inclusion in e-mail |
1917
|
|
|
|
|
|
|
messages. Any buttons or hidden fields are excluded. There is nothing that |
1918
|
|
|
|
|
|
|
indicates whether the user input has errors or not. There is one heading per |
1919
|
|
|
|
|
|
|
field group, and the values from each member of the group are displayed together |
1920
|
|
|
|
|
|
|
in a list. For each field, the title is displayed on one line, then followed by |
1921
|
|
|
|
|
|
|
a blank line, then followed by the user inputs. The title is preceeded by the |
1922
|
|
|
|
|
|
|
text "Q: ", indicating it is the "question". The first optional boolean |
1923
|
|
|
|
|
|
|
argument, EXCLUDE, ensures that any fields that were defined to be "private" are |
1924
|
|
|
|
|
|
|
excluded from this report; by default they are included. The second optional |
1925
|
|
|
|
|
|
|
string argument, EMPTY, specifies the string to use in place of the user's input |
1926
|
|
|
|
|
|
|
where the user left the field empty; by default nothing is shown. The third |
1927
|
|
|
|
|
|
|
optional boolean argument, LIST, causes the resulting form body to be returned |
1928
|
|
|
|
|
|
|
as an array ref whose elements are pieces of the page. If this is false then |
1929
|
|
|
|
|
|
|
everything is returned in a single scalar, and there is a delimiter placed |
1930
|
|
|
|
|
|
|
between each field or group that consists of a line of asterisks ("*"). |
1931
|
|
|
|
|
|
|
|
1932
|
|
|
|
|
|
|
=cut |
1933
|
|
|
|
|
|
|
|
1934
|
|
|
|
|
|
|
###################################################################### |
1935
|
|
|
|
|
|
|
|
1936
|
|
|
|
|
|
|
sub make_text_input_echo { |
1937
|
0
|
|
|
0
|
1
|
|
my ($self, $exclude_private, $empty_field_str, $force_list) = @_; |
1938
|
0
|
0
|
|
|
|
|
defined( $empty_field_str ) or $empty_field_str = $self->{$KEY_EMP_ECH_STR}; |
1939
|
0
|
0
|
|
|
|
|
$self->{$KEY_NORMALIZED} or $self->normalize_field_definitions(); |
1940
|
|
|
|
|
|
|
|
1941
|
0
|
|
|
|
|
|
my $user_input = $self->{$KEY_FIELD_INPUT}; |
1942
|
0
|
|
|
|
|
|
my @input_echo = (); |
1943
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
1944
|
|
|
|
|
|
|
|
1945
|
0
|
|
|
|
|
|
foreach my $defin (@{$self->{$KEY_FIELD_DEFNA}}) { |
|
0
|
|
|
|
|
|
|
1946
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
1947
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
1948
|
|
|
|
|
|
|
|
1949
|
0
|
0
|
|
|
|
|
unless( $FIELD_TYPES{$type}->{$TKEY_EDITAB} ) { |
1950
|
0
|
|
|
|
|
|
next; |
1951
|
|
|
|
|
|
|
} |
1952
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_EXCLUDE_IN_ECHO ) ) { |
1953
|
0
|
|
|
|
|
|
next; |
1954
|
|
|
|
|
|
|
} |
1955
|
0
|
0
|
0
|
|
|
|
if( $exclude_private and $defin->fetch_value( $FKEY_IS_PRIVATE ) ) { |
1956
|
0
|
|
|
|
|
|
next; |
1957
|
|
|
|
|
|
|
} |
1958
|
|
|
|
|
|
|
|
1959
|
0
|
|
|
|
|
|
my @input = grep { $_ ne '' } $user_input->fetch( $name ); |
|
0
|
|
|
|
|
|
|
1960
|
0
|
0
|
|
|
|
|
scalar( @input ) or @input = $empty_field_str; |
1961
|
|
|
|
|
|
|
|
1962
|
0
|
|
|
|
|
|
push( @input_echo, |
1963
|
|
|
|
|
|
|
"\nQ: ".$defin->fetch_value( $FKEY_VISIBLE_TITLE )."\n". |
1964
|
|
|
|
|
|
|
"\n".join( "\n", @input )."\n" ); |
1965
|
|
|
|
|
|
|
} |
1966
|
|
|
|
|
|
|
|
1967
|
0
|
0
|
|
|
|
|
return( $force_list ? \@input_echo : join( |
1968
|
|
|
|
|
|
|
"\n******************************\n", @input_echo ) ); |
1969
|
|
|
|
|
|
|
} |
1970
|
|
|
|
|
|
|
|
1971
|
|
|
|
|
|
|
###################################################################### |
1972
|
|
|
|
|
|
|
|
1973
|
|
|
|
|
|
|
=head2 empty_field_echo_string([ VALUE ]) |
1974
|
|
|
|
|
|
|
|
1975
|
|
|
|
|
|
|
This method is an accessor for the string "empty field echo string" property of |
1976
|
|
|
|
|
|
|
this object, which it returns. If VALUE is defined, this property is set to it. |
1977
|
|
|
|
|
|
|
While making input echo reports, this string is used in place of the user's |
1978
|
|
|
|
|
|
|
input where the user left the field empty; this property is "" by default. |
1979
|
|
|
|
|
|
|
|
1980
|
|
|
|
|
|
|
=cut |
1981
|
|
|
|
|
|
|
|
1982
|
|
|
|
|
|
|
###################################################################### |
1983
|
|
|
|
|
|
|
|
1984
|
|
|
|
|
|
|
sub empty_field_echo_string { |
1985
|
0
|
|
|
0
|
1
|
|
my ($self, $new_value) = @_; |
1986
|
0
|
0
|
|
|
|
|
if( defined( $new_value ) ) { |
1987
|
0
|
|
|
|
|
|
$self->{$KEY_EMP_ECH_STR} = $new_value; |
1988
|
|
|
|
|
|
|
} |
1989
|
0
|
|
|
|
|
|
return( $self->{$KEY_EMP_ECH_STR} ); |
1990
|
|
|
|
|
|
|
} |
1991
|
|
|
|
|
|
|
|
1992
|
|
|
|
|
|
|
###################################################################### |
1993
|
|
|
|
|
|
|
|
1994
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING FORM HTML USING MANUAL FIELD DEFINITIONS |
1995
|
|
|
|
|
|
|
|
1996
|
|
|
|
|
|
|
=head2 field_html_from_defin( DEFIN ) |
1997
|
|
|
|
|
|
|
|
1998
|
|
|
|
|
|
|
This method creates form field html based on a field template DEFIN, and |
1999
|
|
|
|
|
|
|
optionally populates it with user input from a previous form invocation. The |
2000
|
|
|
|
|
|
|
field can be any type, including a group. DEFIN must be either a hash ref or an |
2001
|
|
|
|
|
|
|
MVH object; if neither is provided then this method aborts and returns undef. |
2002
|
|
|
|
|
|
|
This method normally returns a scalar, unless the field template specifies |
2003
|
|
|
|
|
|
|
'list' as an option, in which case an array ref is returned (field groups only). |
2004
|
|
|
|
|
|
|
|
2005
|
|
|
|
|
|
|
=cut |
2006
|
|
|
|
|
|
|
|
2007
|
|
|
|
|
|
|
###################################################################### |
2008
|
|
|
|
|
|
|
|
2009
|
|
|
|
|
|
|
sub field_html_from_defin { |
2010
|
0
|
|
|
0
|
1
|
|
my ($self, $defin) = @_; |
2011
|
0
|
0
|
|
|
|
|
if( UNIVERSAL::isa( $defin, 'Data::MultiValuedHash' ) ) { |
2012
|
0
|
|
|
|
|
|
$defin = $defin->fetch_all(); |
2013
|
|
|
|
|
|
|
} |
2014
|
0
|
0
|
|
|
|
|
ref( $defin ) eq 'HASH' or return( undef ); # improper input so fail |
2015
|
0
|
|
|
|
|
|
$defin = $self->_rename_defin_props( $defin ); |
2016
|
0
|
|
|
|
|
|
return( $self->_make_field_html( $defin ) ); |
2017
|
|
|
|
|
|
|
} |
2018
|
|
|
|
|
|
|
|
2019
|
|
|
|
|
|
|
###################################################################### |
2020
|
|
|
|
|
|
|
|
2021
|
|
|
|
|
|
|
=head1 METHODS FOR MAKING FORM-MAKING FORM DEFINITIONS |
2022
|
|
|
|
|
|
|
|
2023
|
|
|
|
|
|
|
=head2 valid_types([ TYPE ]) |
2024
|
|
|
|
|
|
|
|
2025
|
|
|
|
|
|
|
This method returns a list of all the form field types that this class can |
2026
|
|
|
|
|
|
|
recognize when they are used either in the 'type' attribute of a field |
2027
|
|
|
|
|
|
|
definition, or as the name of an html-field-generating method. This list |
2028
|
|
|
|
|
|
|
contains the same types listed in the "Recognized Form Field Types" of this |
2029
|
|
|
|
|
|
|
documentation. If the optional scalar argument, TYPE, is defined, then this |
2030
|
|
|
|
|
|
|
method will instead return true if TYPE is a valid field type or false if not. |
2031
|
|
|
|
|
|
|
|
2032
|
|
|
|
|
|
|
=cut |
2033
|
|
|
|
|
|
|
|
2034
|
|
|
|
|
|
|
###################################################################### |
2035
|
|
|
|
|
|
|
|
2036
|
|
|
|
|
|
|
sub valid_types { |
2037
|
0
|
|
|
0
|
1
|
|
my ($self, $type) = @_; |
2038
|
0
|
0
|
|
|
|
|
$type and return( exists( $FIELD_TYPES{$type} ) ); |
2039
|
0
|
|
|
|
|
|
my @list = keys %FIELD_TYPES; |
2040
|
0
|
0
|
|
|
|
|
return( wantarray ? @list : \@list ); |
2041
|
|
|
|
|
|
|
} |
2042
|
|
|
|
|
|
|
|
2043
|
|
|
|
|
|
|
###################################################################### |
2044
|
|
|
|
|
|
|
|
2045
|
|
|
|
|
|
|
=head2 valid_multivalue_types([ TYPE ]) |
2046
|
|
|
|
|
|
|
|
2047
|
|
|
|
|
|
|
This method returns true if a form field of the type defined by the optional |
2048
|
|
|
|
|
|
|
scalar argument, TYPE, makes use of a list for its VALUES attribute; otherwise, |
2049
|
|
|
|
|
|
|
only a single VALUE can be used. Note that multiple VALUES also means multiple |
2050
|
|
|
|
|
|
|
LABELS and DEFAULTS where appropriate. If called without any arguments, this |
2051
|
|
|
|
|
|
|
method returns a list of all field types that make use of multiple VALUES. |
2052
|
|
|
|
|
|
|
The list that this method works with is a subset of valid_types(). |
2053
|
|
|
|
|
|
|
|
2054
|
|
|
|
|
|
|
=cut |
2055
|
|
|
|
|
|
|
|
2056
|
|
|
|
|
|
|
###################################################################### |
2057
|
|
|
|
|
|
|
|
2058
|
|
|
|
|
|
|
sub valid_multivalue_types { |
2059
|
0
|
|
|
0
|
1
|
|
my ($self, $type) = @_; |
2060
|
0
|
0
|
0
|
|
|
|
$type and return( exists( $FIELD_TYPES{$type} ) and |
2061
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_MULTIV} ); |
2062
|
0
|
|
|
|
|
|
my @list = grep { $FIELD_TYPES{$_}->{$TKEY_MULTIV} } keys %FIELD_TYPES; |
|
0
|
|
|
|
|
|
|
2063
|
0
|
0
|
|
|
|
|
return( wantarray ? @list : \@list ); |
2064
|
|
|
|
|
|
|
} |
2065
|
|
|
|
|
|
|
|
2066
|
|
|
|
|
|
|
###################################################################### |
2067
|
|
|
|
|
|
|
|
2068
|
|
|
|
|
|
|
=head2 valid_attributes( TYPE[, ATTRIB] ) |
2069
|
|
|
|
|
|
|
|
2070
|
|
|
|
|
|
|
This method returns a list of all the form field definition attributes that this |
2071
|
|
|
|
|
|
|
class can recognize when they are used in defining a field whose type is defined |
2072
|
|
|
|
|
|
|
by the scalar argument, TYPE. If the optional scalar argument, ATTRIB, is |
2073
|
|
|
|
|
|
|
defined, then this method will instead return true if ATTRIB is a valid field |
2074
|
|
|
|
|
|
|
definition attribute or false if not. |
2075
|
|
|
|
|
|
|
|
2076
|
|
|
|
|
|
|
=cut |
2077
|
|
|
|
|
|
|
|
2078
|
|
|
|
|
|
|
###################################################################### |
2079
|
|
|
|
|
|
|
|
2080
|
|
|
|
|
|
|
sub valid_attributes { |
2081
|
0
|
|
|
0
|
1
|
|
my ($self, $type, $attrib) = @_; |
2082
|
0
|
0
|
|
|
|
|
if( $attrib ) { |
2083
|
0
|
0
|
|
|
|
|
$FIELD_TYPES{$type} or return( 0 ); |
2084
|
0
|
|
|
|
|
|
my %valid = map { ( $_ => 1 ) } @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2085
|
0
|
|
|
|
|
|
return( exists( $valid{$type} ) ); |
2086
|
|
|
|
|
|
|
} else { |
2087
|
0
|
|
|
|
|
|
my @list = @{$FIELD_TYPES{$type}->{$TKEY_ATTRIB}}; |
|
0
|
|
|
|
|
|
|
2088
|
0
|
0
|
|
|
|
|
return( wantarray ? @list : \@list ); |
2089
|
|
|
|
|
|
|
} |
2090
|
|
|
|
|
|
|
} |
2091
|
|
|
|
|
|
|
|
2092
|
|
|
|
|
|
|
###################################################################### |
2093
|
|
|
|
|
|
|
|
2094
|
|
|
|
|
|
|
=head1 HTML-MAKING UTILITY METHODS |
2095
|
|
|
|
|
|
|
|
2096
|
|
|
|
|
|
|
=head2 make_table_from_list( SOURCE[, COLS[, ROWS[, ACROSS]]] ) |
2097
|
|
|
|
|
|
|
|
2098
|
|
|
|
|
|
|
This method takes a list of HTML or text elements and arranges them into an |
2099
|
|
|
|
|
|
|
HTML table structure, returning the whole thing as a scalar. The first argument, |
2100
|
|
|
|
|
|
|
SOURCE, is an array ref containing the text we will arrange. The arguments |
2101
|
|
|
|
|
|
|
COLS and ROWS respectively indicate the maximum number of columns and rows that |
2102
|
|
|
|
|
|
|
SOURCE elements are arranged into; the default for each is 1. Because all source |
2103
|
|
|
|
|
|
|
elements must be used, only one of ROWS or COLS is respected; the other is |
2104
|
|
|
|
|
|
|
automatically recalcuated from the first; therefore you only need to provide one. |
2105
|
|
|
|
|
|
|
COLS takes precedence when both are provided. If the fourth argument ACROSS is |
2106
|
|
|
|
|
|
|
true, then source elements are arranged from left-to-right first and then top to |
2107
|
|
|
|
|
|
|
bottom; otherwise, the default has elements arranged from top to bottom first and |
2108
|
|
|
|
|
|
|
left-to-right second. |
2109
|
|
|
|
|
|
|
|
2110
|
|
|
|
|
|
|
=cut |
2111
|
|
|
|
|
|
|
|
2112
|
|
|
|
|
|
|
###################################################################### |
2113
|
|
|
|
|
|
|
|
2114
|
|
|
|
|
|
|
sub make_table_from_list { |
2115
|
0
|
|
|
0
|
1
|
|
my ($self, $ra_list, $max_cols, $max_rows, $acr_first) = @_; |
2116
|
0
|
0
|
|
|
|
|
my @source = ref( $ra_list ) eq 'ARRAY' ? @{$ra_list} : $ra_list; |
|
0
|
|
|
|
|
|
|
2117
|
0
|
|
|
|
|
|
my @table_lines = (); |
2118
|
|
|
|
|
|
|
|
2119
|
|
|
|
|
|
|
# Determine the ROWS x COLS dimensions of our table using the count of |
2120
|
|
|
|
|
|
|
# elements in SOURCE and any pre-defined COLS and ROWS values. Then top |
2121
|
|
|
|
|
|
|
# up the SOURCE array with blanks so that it fills the table evenly; this |
2122
|
|
|
|
|
|
|
# makes sure that rows and columns line up visually, even without aligning. |
2123
|
|
|
|
|
|
|
|
2124
|
0
|
|
|
|
|
|
my $length = scalar( @source ); |
2125
|
0
|
0
|
0
|
|
|
|
if( $max_cols or !$max_rows ) { |
2126
|
0
|
0
|
|
|
|
|
$max_cols < 1 and $max_cols = 1; |
2127
|
0
|
0
|
|
|
|
|
$max_rows = int( $length / $max_cols ) + ($length % $max_cols ? 1 : 0); |
2128
|
|
|
|
|
|
|
} else { |
2129
|
0
|
0
|
|
|
|
|
$max_rows < 1 and $max_rows = 1; |
2130
|
0
|
0
|
|
|
|
|
$max_cols = int( $length / $max_rows ) + ($length % $max_rows ? 1 : 0); |
2131
|
|
|
|
|
|
|
} |
2132
|
0
|
|
|
|
|
|
push( @source, map { ' ' } (1..($max_cols * $max_rows - $length)) ); |
|
0
|
|
|
|
|
|
|
2133
|
|
|
|
|
|
|
|
2134
|
|
|
|
|
|
|
# Option one is to arrange the source elements across first and then down. |
2135
|
|
|
|
|
|
|
|
2136
|
0
|
0
|
|
|
|
|
if( $acr_first ) { |
2137
|
0
|
|
|
|
|
|
push( @table_lines, "\n" );
2138
|
0
|
|
|
|
|
|
foreach my $row_num (1..$max_rows) { |
2139
|
0
|
0
|
|
|
|
|
my @row_source = splice( @source, 0, $max_cols ) or last; |
2140
|
0
|
|
|
|
|
|
my @row_lines = map { " | $_ | " } @row_source;
|
0
|
|
|
|
|
|
|
2141
|
0
|
|
|
|
|
|
push( @table_lines, " | \n".join( "\n", @row_lines )."\n \n" );
2142
|
|
|
|
|
|
|
} |
2143
|
0
|
|
|
|
|
|
push( @table_lines, " | \n" ); |
2144
|
|
|
|
|
|
|
|
2145
|
|
|
|
|
|
|
# Option two is to arrange the source elements down first and then across. |
2146
|
|
|
|
|
|
|
|
2147
|
|
|
|
|
|
|
} else { |
2148
|
0
|
|
|
|
|
|
push( @table_lines, "\n\n" );
2149
|
0
|
|
|
|
|
|
foreach my $col_num (1..$max_cols) { |
2150
|
0
|
0
|
|
|
|
|
my @cell_source = splice( @source, 0, $max_rows ) or last; |
2151
|
0
|
|
|
|
|
|
push( @table_lines, |
2152
|
|
|
|
|
|
|
" | \n".join( " \n", @cell_source )."\n | \n" );
2153
|
|
|
|
|
|
|
} |
2154
|
0
|
|
|
|
|
|
push( @table_lines, " | \n \n" ); |
2155
|
|
|
|
|
|
|
} |
2156
|
|
|
|
|
|
|
|
2157
|
0
|
|
|
|
|
|
return( join( '', @table_lines ) ); |
2158
|
|
|
|
|
|
|
} |
2159
|
|
|
|
|
|
|
|
2160
|
|
|
|
|
|
|
###################################################################### |
2161
|
|
|
|
|
|
|
# _proxy( TYPE, ARGS ) |
2162
|
|
|
|
|
|
|
# This private method is a proxy for the 20 public methods whose names are the |
2163
|
|
|
|
|
|
|
# same as form field types that this class can make. Rather than having 20 |
2164
|
|
|
|
|
|
|
# methods with almost identical code, we put all the code here instead. |
2165
|
|
|
|
|
|
|
# The argument TYPE says which method we are proxying at the moment, and |
2166
|
|
|
|
|
|
|
# the argument ARGS is an array ref having the complete argument list that the |
2167
|
|
|
|
|
|
|
# original method got, including a reference to $self in its first element. |
2168
|
|
|
|
|
|
|
# Note that using these methods is the only opportunity to use positional |
2169
|
|
|
|
|
|
|
# arguments in one's "form field definition"; named still works of course, |
2170
|
|
|
|
|
|
|
# although an MVH object can not be used here. |
2171
|
|
|
|
|
|
|
|
2172
|
|
|
|
|
|
|
sub _proxy { |
2173
|
0
|
|
|
0
|
|
|
my ($self, $type, $ra_args) = @_; |
2174
|
0
|
|
|
|
|
|
shift( @{$ra_args} ); # first element is an extra ref to $self |
|
0
|
|
|
|
|
|
|
2175
|
0
|
|
|
|
|
|
my $defin = $self->params_to_hash( $ra_args, $self->{$KEY_AUTO_POSIT}, |
2176
|
0
|
|
|
|
|
|
@{$FIELD_TYPES{$type}->{$TKEY_PARSER}}, 1 ); |
2177
|
0
|
|
|
|
|
|
$defin->{$FKEY_TYPE} = $type; |
2178
|
0
|
|
|
|
|
|
return( $self->_make_field_html( $defin ) ); |
2179
|
|
|
|
|
|
|
} |
2180
|
|
|
|
|
|
|
|
2181
|
|
|
|
|
|
|
###################################################################### |
2182
|
|
|
|
|
|
|
# _rename_defin_groups( DEFIN ) |
2183
|
|
|
|
|
|
|
# This private method takes a form field definition and resolves its property |
2184
|
|
|
|
|
|
|
# aliases, returning a new form field definition. DEFIN must be a hash ref and |
2185
|
|
|
|
|
|
|
# this method returns a hash ref. |
2186
|
|
|
|
|
|
|
|
2187
|
|
|
|
|
|
|
sub _rename_defin_props { |
2188
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2189
|
|
|
|
|
|
|
|
2190
|
|
|
|
|
|
|
# Determine our field type. Note that we have to do a bit of parsing ourself |
2191
|
|
|
|
|
|
|
# to get the type because we need the type to know how to parse definition. |
2192
|
|
|
|
|
|
|
|
2193
|
0
|
|
|
|
|
|
my %lc_defin = map { ( lc($_) => $defin->{$_} ) } sort keys %{$defin}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2194
|
0
|
|
0
|
|
|
|
my $type = $defin->{lc($FKEY_TYPE)} || $defin->{"-".lc($FKEY_TYPE)}; |
2195
|
0
|
0
|
|
|
|
|
ref( $type ) eq 'ARRAY' and $type = $type->[0]; |
2196
|
0
|
0
|
|
|
|
|
$FIELD_TYPES{$type} or $type = $self->{$KEY_DEF_FF_TYPE}; |
2197
|
|
|
|
|
|
|
|
2198
|
|
|
|
|
|
|
# Make sure that field definition has appropriately named properties. |
2199
|
|
|
|
|
|
|
|
2200
|
0
|
|
|
|
|
|
$defin = $self->params_to_hash( [$defin], 0, |
2201
|
0
|
|
|
|
|
|
@{$FIELD_TYPES{$type}->{$TKEY_PARSER}}, 1 ); |
2202
|
0
|
|
|
|
|
|
$defin->{$FKEY_TYPE} = $type; |
2203
|
|
|
|
|
|
|
|
2204
|
0
|
|
|
|
|
|
return( $defin ); |
2205
|
|
|
|
|
|
|
} |
2206
|
|
|
|
|
|
|
|
2207
|
|
|
|
|
|
|
###################################################################### |
2208
|
|
|
|
|
|
|
# _make_field_html( DEFIN ) |
2209
|
|
|
|
|
|
|
# This private method takes a form field definition, which has had its property |
2210
|
|
|
|
|
|
|
# aliases resolved, and creates form field html based on it. DEFIN must be a |
2211
|
|
|
|
|
|
|
# hash ref or MVH object. This method serves as a dispatch for more specialized |
2212
|
|
|
|
|
|
|
# HTML-making private methods, and it takes care of issues common to all field |
2213
|
|
|
|
|
|
|
# types so the specialized methods don't each have to do them. This method |
2214
|
|
|
|
|
|
|
# copies its input DEFIN and proceeds to change the copy in the following ways |
2215
|
|
|
|
|
|
|
# before dispatch: 1. 'type' is made valid; 2. 'name' is made defined; |
2216
|
|
|
|
|
|
|
# 3. previous user-input is incorporated into 'default'; 4. miscellaneous DEFIN |
2217
|
|
|
|
|
|
|
# properties are grouped into 'tag_attr'. After dispatch, group fields are |
2218
|
|
|
|
|
|
|
# in array refs, and so this method handles joining them together as needed. |
2219
|
|
|
|
|
|
|
|
2220
|
|
|
|
|
|
|
sub _make_field_html { |
2221
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2222
|
0
|
|
|
|
|
|
$defin = Data::MultiValuedHash->new( 1, $defin ); # copy input |
2223
|
|
|
|
|
|
|
|
2224
|
|
|
|
|
|
|
# Make sure the field definition has a valid field type. |
2225
|
|
|
|
|
|
|
|
2226
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
2227
|
0
|
0
|
|
|
|
|
unless( $FIELD_TYPES{$type} ) { |
2228
|
0
|
|
|
|
|
|
$type = $self->{$KEY_DEF_FF_TYPE}; |
2229
|
0
|
|
|
|
|
|
$defin->store( $FKEY_TYPE, $type ); |
2230
|
|
|
|
|
|
|
} |
2231
|
|
|
|
|
|
|
|
2232
|
|
|
|
|
|
|
# Make sure the field definition has field name. |
2233
|
|
|
|
|
|
|
|
2234
|
0
|
0
|
|
|
|
|
unless( $defin->exists( $FKEY_NAME ) ) { |
2235
|
0
|
|
|
|
|
|
$defin->store( $FKEY_NAME, $self->{$KEY_DEF_FF_NAME} ); |
2236
|
|
|
|
|
|
|
} |
2237
|
|
|
|
|
|
|
|
2238
|
|
|
|
|
|
|
# Restore field values that user entered during previous form invocation, |
2239
|
|
|
|
|
|
|
# unless this is a new form or the coded value has priority on repeat. |
2240
|
|
|
|
|
|
|
# Filter out any empty strings while we're at it, and HTML encode to prevent |
2241
|
|
|
|
|
|
|
# disrupting the new HTML page. |
2242
|
|
|
|
|
|
|
|
2243
|
0
|
0
|
0
|
|
|
|
unless( $self->{$KEY_NEW_FORM} or $defin->fetch_value( $FKEY_OVERRIDE ) ) { |
2244
|
0
|
|
|
|
|
|
my $name = $defin->fetch_value( $FKEY_NAME ); |
2245
|
0
|
|
|
|
|
|
my @input = grep { $_ ne '' } $self->{$KEY_FIELD_INPUT}->fetch( $name ); |
|
0
|
|
|
|
|
|
|
2246
|
0
|
|
|
|
|
|
foreach (@input) { |
2247
|
0
|
|
|
|
|
|
s/&/&/g; |
2248
|
0
|
|
|
|
|
|
s/\"/"/g; |
2249
|
0
|
|
|
|
|
|
s/>/>/g; |
2250
|
0
|
|
|
|
|
|
s/</g; |
2251
|
|
|
|
|
|
|
} |
2252
|
0
|
|
|
|
|
|
$defin->store( $FKEY_DEFAULTS, \@input ); |
2253
|
|
|
|
|
|
|
} |
2254
|
|
|
|
|
|
|
|
2255
|
|
|
|
|
|
|
# Make sure the field definition's misc tag attrib are properly formatted. |
2256
|
|
|
|
|
|
|
|
2257
|
0
|
|
|
|
|
|
my $tag_attr = $defin->fetch_value( $FKEY_TAG_ATTR ); |
2258
|
0
|
0
|
|
|
|
|
ref( $tag_attr ) eq 'HASH' or $tag_attr = {}; |
2259
|
0
|
|
|
|
|
|
%{$tag_attr} = ( |
|
0
|
|
|
|
|
|
|
2260
|
|
|
|
|
|
|
$FIELD_TYPES{$type}->{$TKEY_FLDGRP} ? |
2261
|
|
|
|
|
|
|
$defin->fetch_all( \@SPECIAL_ATTRIB, 1 ) : |
2262
|
|
|
|
|
|
|
$defin->fetch_first( \@SPECIAL_ATTRIB, 1 ), |
2263
|
0
|
0
|
|
|
|
|
%{$tag_attr}, |
2264
|
|
|
|
|
|
|
); |
2265
|
0
|
|
|
|
|
|
$defin->store( $FKEY_TAG_ATTR, $tag_attr ); |
2266
|
|
|
|
|
|
|
|
2267
|
|
|
|
|
|
|
# Make sure the field group definitions have a valid member count. |
2268
|
|
|
|
|
|
|
# This setting does not affect checkbox_group or radio_group fields. |
2269
|
|
|
|
|
|
|
|
2270
|
0
|
0
|
|
|
|
|
if( $FIELD_TYPES{$type}->{$TKEY_FLDGRP} ) { |
2271
|
0
|
|
|
|
|
|
my $wanted = $defin->fetch_value( $FKEY_MIN_GRP_COUNT ); |
2272
|
0
|
0
|
|
|
|
|
unless( defined( $wanted ) ) { |
2273
|
0
|
|
|
|
|
|
my $first_default = $defin->fetch_value( $FKEY_DEFAULTS ); |
2274
|
0
|
0
|
|
|
|
|
if( ref( $first_default ) eq 'HASH' ) { |
2275
|
0
|
|
|
|
|
|
$wanted = grep { $first_default->{$_} } keys %{$first_default}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2276
|
|
|
|
|
|
|
} else { |
2277
|
0
|
|
|
|
|
|
$wanted = $defin->count( $FKEY_DEFAULTS ); |
2278
|
|
|
|
|
|
|
} |
2279
|
|
|
|
|
|
|
} |
2280
|
0
|
0
|
|
|
|
|
$wanted < 1 and $wanted = 1; |
2281
|
0
|
|
|
|
|
|
$defin->store( $FKEY_MIN_GRP_COUNT, $wanted ); |
2282
|
|
|
|
|
|
|
} |
2283
|
|
|
|
|
|
|
|
2284
|
|
|
|
|
|
|
# Determine which of our private methods will make HTML for this field type. |
2285
|
|
|
|
|
|
|
|
2286
|
0
|
|
|
|
|
|
my $method = $FIELD_TYPES{$type}->{$TKEY_METHOD}; |
2287
|
|
|
|
|
|
|
|
2288
|
|
|
|
|
|
|
# Make the field HTML. |
2289
|
|
|
|
|
|
|
|
2290
|
0
|
|
|
|
|
|
my $html = $self->$method( $defin ); |
2291
|
|
|
|
|
|
|
|
2292
|
|
|
|
|
|
|
# If the field type is a group, then $html is an array ref with a |
2293
|
|
|
|
|
|
|
# group member in each array element. So, unless the list property is true, |
2294
|
|
|
|
|
|
|
# join the group into a scalar, delim by linebreaks or grouped in a table. |
2295
|
|
|
|
|
|
|
|
2296
|
0
|
0
|
|
|
|
|
if( ref( $html ) eq 'ARRAY' ) { |
2297
|
0
|
|
|
|
|
|
$html = $self->_join_field_group_html( $defin, $html ); |
2298
|
|
|
|
|
|
|
} |
2299
|
|
|
|
|
|
|
|
2300
|
|
|
|
|
|
|
# Return the new field HTML. |
2301
|
|
|
|
|
|
|
|
2302
|
0
|
|
|
|
|
|
return( $html ); |
2303
|
|
|
|
|
|
|
} |
2304
|
|
|
|
|
|
|
|
2305
|
|
|
|
|
|
|
###################################################################### |
2306
|
|
|
|
|
|
|
# _make_textarea_html( DEFIN ) |
2307
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2308
|
|
|
|
|
|
|
# single "" form tags. |
2309
|
|
|
|
|
|
|
|
2310
|
|
|
|
|
|
|
sub _make_textarea_html { |
2311
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2312
|
|
|
|
|
|
|
|
2313
|
|
|
|
|
|
|
# Set up default attributes common to textarea tags. |
2314
|
|
|
|
|
|
|
|
2315
|
0
|
|
|
|
|
|
my %params = ( |
2316
|
0
|
|
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2317
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2318
|
|
|
|
|
|
|
); |
2319
|
0
|
|
|
|
|
|
my $default = $defin->fetch_value( $FKEY_DEFAULTS ); |
2320
|
|
|
|
|
|
|
|
2321
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2322
|
|
|
|
|
|
|
|
2323
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2324
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag( 'textarea', \%params, $default ) ); |
2325
|
|
|
|
|
|
|
} |
2326
|
|
|
|
|
|
|
|
2327
|
|
|
|
|
|
|
###################################################################### |
2328
|
|
|
|
|
|
|
# _make_textarea_group_html( DEFIN ) |
2329
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2330
|
|
|
|
|
|
|
# a group of "" form tags. |
2331
|
|
|
|
|
|
|
|
2332
|
|
|
|
|
|
|
sub _make_textarea_group_html { |
2333
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2334
|
|
|
|
|
|
|
|
2335
|
|
|
|
|
|
|
# Set up default attributes common to textarea tags. |
2336
|
|
|
|
|
|
|
|
2337
|
0
|
|
|
|
|
|
my %params = ( |
2338
|
0
|
|
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2339
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2340
|
|
|
|
|
|
|
); |
2341
|
0
|
|
|
|
|
|
my @defaults = $defin->fetch( $FKEY_DEFAULTS ); |
2342
|
|
|
|
|
|
|
|
2343
|
|
|
|
|
|
|
# Make sure we have enough group members. |
2344
|
|
|
|
|
|
|
|
2345
|
0
|
|
|
|
|
|
my $wanted = $defin->fetch_value( $FKEY_MIN_GRP_COUNT ); |
2346
|
0
|
|
|
|
|
|
my $have = @defaults; |
2347
|
0
|
0
|
|
|
|
|
if( $have < $wanted ) { |
2348
|
0
|
|
|
|
|
|
push( @defaults, [map { '' } (1..($wanted - $have))] ); |
|
0
|
|
|
|
|
|
|
2349
|
|
|
|
|
|
|
} |
2350
|
|
|
|
|
|
|
|
2351
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2352
|
|
|
|
|
|
|
|
2353
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2354
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag_group( |
2355
|
|
|
|
|
|
|
'textarea', \%params, \@defaults, 1 ) ); |
2356
|
|
|
|
|
|
|
} |
2357
|
|
|
|
|
|
|
|
2358
|
|
|
|
|
|
|
###################################################################### |
2359
|
|
|
|
|
|
|
# _make_input_html( DEFIN ) |
2360
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2361
|
|
|
|
|
|
|
# single "" form tags. |
2362
|
|
|
|
|
|
|
|
2363
|
|
|
|
|
|
|
sub _make_input_html { |
2364
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2365
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
2366
|
|
|
|
|
|
|
|
2367
|
|
|
|
|
|
|
# Set up default attributes common to all input tags. |
2368
|
|
|
|
|
|
|
|
2369
|
0
|
|
|
|
|
|
my %params = ( |
2370
|
0
|
|
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2371
|
|
|
|
|
|
|
type => $INPUT_TAG_IMPL_TYPE{$type}, |
2372
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2373
|
|
|
|
|
|
|
value => $defin->fetch_value( $FKEY_DEFAULTS ), |
2374
|
|
|
|
|
|
|
); |
2375
|
0
|
|
|
|
|
|
my $label = ''; |
2376
|
|
|
|
|
|
|
|
2377
|
|
|
|
|
|
|
# Set up attributes that are unique to check boxes and radio buttons. |
2378
|
|
|
|
|
|
|
# One difference is that user input affects the "checked" attribute |
2379
|
|
|
|
|
|
|
# instead of "value". |
2380
|
|
|
|
|
|
|
|
2381
|
0
|
0
|
0
|
|
|
|
if( $type eq 'checkbox' or $type eq 'radio' ) { |
2382
|
0
|
|
|
|
|
|
$params{value} = $defin->fetch_value( $FKEY_VALUES ); |
2383
|
0
|
0
|
|
|
|
|
defined( $params{value} ) or $params{value} = 'on'; |
2384
|
0
|
|
|
|
|
|
$params{checked} = $defin->fetch_value( $FKEY_DEFAULTS ); |
2385
|
0
|
|
|
|
|
|
$label = $defin->fetch_value( $FKEY_LABELS ); |
2386
|
0
|
0
|
|
|
|
|
defined( $label ) or $label = $params{name}; |
2387
|
0
|
0
|
|
|
|
|
$defin->fetch_value( $FKEY_NOLABELS ) and $label = ''; |
2388
|
|
|
|
|
|
|
|
2389
|
|
|
|
|
|
|
# For most input tag types, an empty "value" attribute is useless so |
2390
|
|
|
|
|
|
|
# get rid of it. For buttons an empty value leads to no button label. |
2391
|
|
|
|
|
|
|
|
2392
|
|
|
|
|
|
|
} else { |
2393
|
0
|
0
|
|
|
|
|
$params{value} eq '' and delete( $params{value} ); |
2394
|
|
|
|
|
|
|
} |
2395
|
|
|
|
|
|
|
|
2396
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2397
|
|
|
|
|
|
|
|
2398
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2399
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag( 'input', \%params, $label ) ); |
2400
|
|
|
|
|
|
|
} |
2401
|
|
|
|
|
|
|
|
2402
|
|
|
|
|
|
|
###################################################################### |
2403
|
|
|
|
|
|
|
# _make_input_group_html( DEFIN ) |
2404
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2405
|
|
|
|
|
|
|
# a group of "" form tags. |
2406
|
|
|
|
|
|
|
|
2407
|
|
|
|
|
|
|
sub _make_input_group_html { |
2408
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2409
|
0
|
|
|
|
|
|
my $type = $defin->fetch_value( $FKEY_TYPE ); |
2410
|
|
|
|
|
|
|
|
2411
|
|
|
|
|
|
|
# Set up default attributes common to all input tags. |
2412
|
|
|
|
|
|
|
|
2413
|
0
|
|
|
|
|
|
my %params = ( |
2414
|
0
|
|
0
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2415
|
|
|
|
|
|
|
type => $INPUT_TAG_IMPL_TYPE{$type}, |
2416
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2417
|
|
|
|
|
|
|
value => scalar( $defin->fetch( $FKEY_DEFAULTS ) ) || [], |
2418
|
|
|
|
|
|
|
); |
2419
|
0
|
|
|
|
|
|
my @labels = (); |
2420
|
|
|
|
|
|
|
|
2421
|
|
|
|
|
|
|
# Set up attributes that are unique to checkboxes and radio buttons. |
2422
|
|
|
|
|
|
|
# One difference is that user input affects the "checked" attribute |
2423
|
|
|
|
|
|
|
# instead of "value". |
2424
|
|
|
|
|
|
|
|
2425
|
0
|
0
|
0
|
|
|
|
if( $type eq 'checkbox_group' or $type eq 'radio_group' ) { |
2426
|
0
|
|
0
|
|
|
|
my $ra_values = $defin->fetch( $FKEY_VALUES ) || ['on']; |
2427
|
0
|
|
|
|
|
|
$params{value} = $ra_values; |
2428
|
|
|
|
|
|
|
|
2429
|
|
|
|
|
|
|
# The definition property "defaults" may be either an array ref |
2430
|
|
|
|
|
|
|
# or a hash ref. If it is a hash ref then the hash keys would |
2431
|
|
|
|
|
|
|
# correspond to field values and the hash values would be either |
2432
|
|
|
|
|
|
|
# true or false to indicate if it is selected. If it is an array |
2433
|
|
|
|
|
|
|
# ref then the array elements would be a list of field values, |
2434
|
|
|
|
|
|
|
# all of which are selected. This code block takes either |
2435
|
|
|
|
|
|
|
# variable type and coerces the data into an array ref that has |
2436
|
|
|
|
|
|
|
# the same number of elements as there are field values, and each |
2437
|
|
|
|
|
|
|
# corresponding element is either true or false; this format is |
2438
|
|
|
|
|
|
|
# what HTML::EasyTags needs as input. |
2439
|
|
|
|
|
|
|
|
2440
|
0
|
|
0
|
|
|
|
my $ra_defaults = $defin->fetch( $FKEY_DEFAULTS ) || []; # array |
2441
|
0
|
0
|
|
|
|
|
if( ref( $ra_defaults->[0] ) eq 'HASH' ) { |
2442
|
0
|
|
|
|
|
|
$ra_defaults = $ra_defaults->[0]; # hash |
2443
|
|
|
|
|
|
|
} |
2444
|
0
|
0
|
|
|
|
|
if( ref( $ra_defaults ) eq 'ARRAY' ) { |
2445
|
0
|
|
|
|
|
|
$ra_defaults = {map { ( $_ => 1 ) } @{$ra_defaults}}; # hash |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2446
|
|
|
|
|
|
|
} |
2447
|
0
|
|
|
|
|
|
$ra_defaults = [map { $ra_defaults->{$_} } @{$ra_values}]; # ary |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2448
|
0
|
|
|
|
|
|
$params{checked} = $ra_defaults; |
2449
|
|
|
|
|
|
|
|
2450
|
|
|
|
|
|
|
# The definition property "labels" may be either an array ref |
2451
|
|
|
|
|
|
|
# or a hash ref. If it is a hash ref then the hash keys would |
2452
|
|
|
|
|
|
|
# correspond to field values and the hash values would be the |
2453
|
|
|
|
|
|
|
# labels associated with them; this is coerced into an array. |
2454
|
|
|
|
|
|
|
# If it is an array ref then the elements already are |
2455
|
|
|
|
|
|
|
# counterparts to the field value list. If any labels are |
2456
|
|
|
|
|
|
|
# undefined then the appropriate field value is used as a label. |
2457
|
|
|
|
|
|
|
|
2458
|
0
|
|
0
|
|
|
|
my $ra_labels = $defin->fetch( $FKEY_LABELS ) || []; # array |
2459
|
0
|
0
|
|
|
|
|
if( ref( $ra_labels->[0] ) eq 'HASH' ) { |
2460
|
0
|
|
|
|
|
|
$ra_labels = $ra_labels->[0]; # hash |
2461
|
0
|
|
|
|
|
|
$ra_labels = [map { $ra_labels->{$_} } @{$ra_values}]; # ary |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2462
|
|
|
|
|
|
|
} |
2463
|
0
|
|
|
|
|
|
foreach my $index (0..$#{$ra_values}) { |
|
0
|
|
|
|
|
|
|
2464
|
0
|
0
|
|
|
|
|
unless( defined( $ra_labels->[$index] ) ) { |
2465
|
0
|
|
|
|
|
|
$ra_labels->[$index] = $ra_values->[$index]; |
2466
|
|
|
|
|
|
|
} |
2467
|
|
|
|
|
|
|
} |
2468
|
0
|
0
|
|
|
|
|
$defin->fetch_value( $FKEY_NOLABELS ) and $ra_labels = []; |
2469
|
0
|
|
|
|
|
|
@labels = @{$ra_labels}; |
|
0
|
|
|
|
|
|
|
2470
|
|
|
|
|
|
|
|
2471
|
|
|
|
|
|
|
# Make sure we have enough group members. |
2472
|
|
|
|
|
|
|
|
2473
|
|
|
|
|
|
|
} else { |
2474
|
0
|
|
|
|
|
|
my $wanted = $defin->fetch_value( $FKEY_MIN_GRP_COUNT ); |
2475
|
0
|
|
|
|
|
|
my $have = @{$params{value}}; |
|
0
|
|
|
|
|
|
|
2476
|
0
|
0
|
|
|
|
|
if( $have < $wanted ) { |
2477
|
0
|
|
|
|
|
|
push( @{$params{value}}, [map { '' } (1..($wanted - $have))] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
} |
2479
|
|
|
|
|
|
|
} |
2480
|
|
|
|
|
|
|
|
2481
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2482
|
|
|
|
|
|
|
|
2483
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2484
|
0
|
|
|
|
|
|
return( $tagmaker->make_html_tag_group( 'input', \%params, \@labels, 1 ) ); |
2485
|
|
|
|
|
|
|
} |
2486
|
|
|
|
|
|
|
|
2487
|
|
|
|
|
|
|
###################################################################### |
2488
|
|
|
|
|
|
|
# _make_select_html( DEFIN ) |
2489
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2490
|
|
|
|
|
|
|
# single "" form tags, which include a group of |
2491
|
|
|
|
|
|
|
|
2492
|
|
|
|
|
|
|
sub _make_select_html { |
2493
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2494
|
|
|
|
|
|
|
|
2495
|
|
|
|
|
|
|
# Set up default attributes for the option tags. |
2496
|
|
|
|
|
|
|
|
2497
|
0
|
|
0
|
|
|
|
my $ra_values = $defin->fetch( $FKEY_VALUES ) || ['on']; |
2498
|
|
|
|
|
|
|
|
2499
|
|
|
|
|
|
|
# The definition property "defaults" is handled the same way as the |
2500
|
|
|
|
|
|
|
# same property for checkbox groups, so refer to the documentation there. |
2501
|
|
|
|
|
|
|
|
2502
|
0
|
|
0
|
|
|
|
my $ra_defaults = $defin->fetch( $FKEY_DEFAULTS ) || []; # array |
2503
|
0
|
0
|
|
|
|
|
if( ref( $ra_defaults->[0] ) eq 'HASH' ) { |
2504
|
0
|
|
|
|
|
|
$ra_defaults = $ra_defaults->[0]; # hash |
2505
|
|
|
|
|
|
|
} |
2506
|
0
|
0
|
|
|
|
|
if( ref( $ra_defaults ) eq 'ARRAY' ) { |
2507
|
0
|
|
|
|
|
|
$ra_defaults = {map { ( $_ => 1 ) } @{$ra_defaults}}; # hash |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2508
|
|
|
|
|
|
|
} |
2509
|
0
|
|
|
|
|
|
$ra_defaults = [map { $ra_defaults->{$_} } @{$ra_values}]; # ary |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2510
|
|
|
|
|
|
|
|
2511
|
|
|
|
|
|
|
# The definition property "labels" is handled the same way as the |
2512
|
|
|
|
|
|
|
# same property for checkbox groups, so refer to the documentation there. |
2513
|
|
|
|
|
|
|
|
2514
|
0
|
|
0
|
|
|
|
my $ra_labels = $defin->fetch( $FKEY_LABELS ) || []; # array |
2515
|
0
|
0
|
|
|
|
|
if( ref( $ra_labels->[0] ) eq 'HASH' ) { |
2516
|
0
|
|
|
|
|
|
$ra_labels = $ra_labels->[0]; # hash |
2517
|
0
|
|
|
|
|
|
$ra_labels = [map { $ra_labels->{$_} } @{$ra_values}]; # ary |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2518
|
|
|
|
|
|
|
} |
2519
|
0
|
|
|
|
|
|
foreach my $index (0..$#{$ra_values}) { |
|
0
|
|
|
|
|
|
|
2520
|
0
|
0
|
|
|
|
|
unless( defined( $ra_labels->[$index] ) ) { |
2521
|
0
|
|
|
|
|
|
$ra_labels->[$index] = $ra_values->[$index]; |
2522
|
|
|
|
|
|
|
} |
2523
|
|
|
|
|
|
|
} |
2524
|
|
|
|
|
|
|
|
2525
|
|
|
|
|
|
|
# Set up default attributes common to all select tags. |
2526
|
|
|
|
|
|
|
|
2527
|
0
|
|
|
|
|
|
my %params = ( |
2528
|
0
|
|
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2529
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2530
|
|
|
|
|
|
|
); |
2531
|
0
|
|
0
|
|
|
|
$params{size} ||= scalar( @{$ra_values} ); |
|
0
|
|
|
|
|
|
|
2532
|
|
|
|
|
|
|
|
2533
|
|
|
|
|
|
|
# Set up attributes that are unique to popup menus. They are |
2534
|
|
|
|
|
|
|
# different in that only one item can be displayed at a time, and |
2535
|
|
|
|
|
|
|
# correspondingly the user can only choose one item at a time. |
2536
|
|
|
|
|
|
|
|
2537
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_TYPE ) eq 'popup_menu' ) { |
2538
|
0
|
|
|
|
|
|
$params{size} = 1; |
2539
|
0
|
|
|
|
|
|
$params{multiple} = 0; |
2540
|
|
|
|
|
|
|
} |
2541
|
|
|
|
|
|
|
|
2542
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2543
|
|
|
|
|
|
|
|
2544
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2545
|
0
|
|
|
|
|
|
return( join( '', |
2546
|
|
|
|
|
|
|
$tagmaker->make_html_tag( 'select', \%params, undef, 'start' ), |
2547
|
0
|
|
|
|
|
|
@{$tagmaker->make_html_tag_group( 'option', { value => $ra_values, |
2548
|
|
|
|
|
|
|
selected => $ra_defaults }, $ra_labels, 1 )}, |
2549
|
|
|
|
|
|
|
$tagmaker->make_html_tag( 'select', {}, undef, 'end' ), |
2550
|
|
|
|
|
|
|
) ); |
2551
|
|
|
|
|
|
|
} |
2552
|
|
|
|
|
|
|
|
2553
|
|
|
|
|
|
|
###################################################################### |
2554
|
|
|
|
|
|
|
# _make_select_group_html( DEFIN ) |
2555
|
|
|
|
|
|
|
# This private method assists _make_field_html() by specializing in making |
2556
|
|
|
|
|
|
|
# a group of "" form tags. |
2557
|
|
|
|
|
|
|
|
2558
|
|
|
|
|
|
|
sub _make_select_group_html { |
2559
|
0
|
|
|
0
|
|
|
my ($self, $defin) = @_; |
2560
|
|
|
|
|
|
|
|
2561
|
|
|
|
|
|
|
# Set up default attributes for the option tags. |
2562
|
|
|
|
|
|
|
|
2563
|
0
|
|
0
|
|
|
|
my $ra_values = $defin->fetch( $FKEY_VALUES ) || ['on']; |
2564
|
|
|
|
|
|
|
|
2565
|
|
|
|
|
|
|
# The definition property "labels" is handled the same way as the |
2566
|
|
|
|
|
|
|
# same property for checkbox groups, so refer to the documentation there. |
2567
|
|
|
|
|
|
|
|
2568
|
0
|
|
0
|
|
|
|
my $ra_labels = $defin->fetch( $FKEY_LABELS ) || []; # array |
2569
|
0
|
0
|
|
|
|
|
if( ref( $ra_labels->[0] ) eq 'HASH' ) { |
2570
|
0
|
|
|
|
|
|
$ra_labels = $ra_labels->[0]; # hash |
2571
|
0
|
|
|
|
|
|
$ra_labels = [map { $ra_labels->{$_} } @{$ra_values}]; # ary |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2572
|
|
|
|
|
|
|
} |
2573
|
0
|
|
|
|
|
|
foreach my $index (0..$#{$ra_values}) { |
|
0
|
|
|
|
|
|
|
2574
|
0
|
0
|
|
|
|
|
unless( defined( $ra_labels->[$index] ) ) { |
2575
|
0
|
|
|
|
|
|
$ra_labels->[$index] = $ra_values->[$index]; |
2576
|
|
|
|
|
|
|
} |
2577
|
|
|
|
|
|
|
} |
2578
|
|
|
|
|
|
|
|
2579
|
|
|
|
|
|
|
# Set up default attributes common to all select tags. |
2580
|
|
|
|
|
|
|
|
2581
|
0
|
|
|
|
|
|
my %params = ( |
2582
|
0
|
|
|
|
|
|
%{$defin->fetch_value( $FKEY_TAG_ATTR )}, |
2583
|
|
|
|
|
|
|
name => $defin->fetch_value( $FKEY_NAME ), |
2584
|
|
|
|
|
|
|
); |
2585
|
0
|
|
0
|
|
|
|
$params{size} ||= scalar( @{$ra_values} ); |
|
0
|
|
|
|
|
|
|
2586
|
|
|
|
|
|
|
|
2587
|
|
|
|
|
|
|
# Set up attributes that are unique to popup menus. They are |
2588
|
|
|
|
|
|
|
# different in that only one item can be displayed at a time, and |
2589
|
|
|
|
|
|
|
# correspondingly the user can only choose one item at a time. |
2590
|
|
|
|
|
|
|
|
2591
|
0
|
0
|
|
|
|
|
if( $defin->fetch_value( $FKEY_TYPE ) eq 'popup_menu_group' ) { |
2592
|
0
|
|
|
|
|
|
$params{size} = 1; |
2593
|
0
|
|
|
|
|
|
$params{multiple} = 0; |
2594
|
|
|
|
|
|
|
} |
2595
|
|
|
|
|
|
|
|
2596
|
|
|
|
|
|
|
# Make sure we have a list of valid default values, and hash of said also. |
2597
|
|
|
|
|
|
|
# The valid list is an intersection of current defaults and field values. |
2598
|
|
|
|
|
|
|
|
2599
|
0
|
|
|
|
|
|
my @defaults = $defin->fetch( $FKEY_DEFAULTS ); |
2600
|
0
|
|
|
|
|
|
my $rh_defaults = $defaults[0]; |
2601
|
0
|
0
|
|
|
|
|
unless( ref( $rh_defaults ) eq 'HASH' ) { |
2602
|
0
|
|
|
|
|
|
$rh_defaults = {map { ( $_ => 1 ) } @defaults}; |
|
0
|
|
|
|
|
|
|
2603
|
|
|
|
|
|
|
} |
2604
|
0
|
|
|
|
|
|
@defaults = grep { $rh_defaults->{$_} } @defaults; |
|
0
|
|
|
|
|
|
|
2605
|
|
|
|
|
|
|
|
2606
|
|
|
|
|
|
|
# Make sure we have enough group members. |
2607
|
|
|
|
|
|
|
|
2608
|
0
|
|
|
|
|
|
my $wanted = $defin->fetch_value( $FKEY_MIN_GRP_COUNT ); |
2609
|
0
|
|
|
|
|
|
my $have = @defaults; |
2610
|
0
|
0
|
|
|
|
|
if( $have < $wanted ) { |
2611
|
0
|
|
|
|
|
|
push( @defaults, [map { '' } (1..($wanted - $have))] ); |
|
0
|
|
|
|
|
|
|
2612
|
|
|
|
|
|
|
} |
2613
|
|
|
|
|
|
|
|
2614
|
|
|
|
|
|
|
# Make the field HTML and return it. |
2615
|
|
|
|
|
|
|
|
2616
|
0
|
|
|
|
|
|
my $tagmaker = $self->{$KEY_TAG_MAKER}; |
2617
|
0
|
|
|
|
|
|
my @field_list = (); |
2618
|
0
|
|
|
|
|
|
foreach my $default (@defaults) { |
2619
|
0
|
|
|
|
|
|
my $ra_defaults = [map { $_ eq $default } @{$ra_values}]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2620
|
0
|
|
|
|
|
|
push( @field_list, join( '', |
2621
|
|
|
|
|
|
|
$tagmaker->make_html_tag( 'select', \%params, undef, 'start' ), |
2622
|
0
|
|
|
|
|
|
@{$tagmaker->make_html_tag_group( 'option', { value => $ra_values, |
2623
|
|
|
|
|
|
|
selected => $ra_defaults }, $ra_labels, 1 )}, |
2624
|
|
|
|
|
|
|
$tagmaker->make_html_tag( 'select', {}, undef, 'end' ), |
2625
|
|
|
|
|
|
|
) ); |
2626
|
|
|
|
|
|
|
} |
2627
|
0
|
|
|
|
|
|
return( \@field_list ); |
2628
|
|
|
|
|
|
|
} |
2629
|
|
|
|
|
|
|
|
2630
|
|
|
|
|
|
|
###################################################################### |
2631
|
|
|
|
|
|
|
# _join_field_group_html( DEFIN, LIST ) |
2632
|
|
|
|
|
|
|
# This private method assists _make_field_html() by joining together a list of |
2633
|
|
|
|
|
|
|
# field group html, LIST, according to the field preferences in DEFIN. This |
2634
|
|
|
|
|
|
|
# method will check a series of field definition properties in order until it |
2635
|
|
|
|
|
|
|
# finds one that is true; it then joins the fields in accordance with that one. |
2636
|
|
|
|
|
|
|
# These are the properties in order of precedence: 1. 'list' causes the LIST |
2637
|
|
|
|
|
|
|
# elements to be returned as is (in an array ref), one field per element; |
2638
|
|
|
|
|
|
|
# 2. 'linebreak' creates a scalar with group members delimited by tags; |
2639
|
|
|
|
|
|
|
# 3. 'table_cols' or 'table_rows' causes the group members to be formatted into |
2640
|
|
|
|
|
|
|
# an HTML table, returned as a scalar; 4. otherwise, we join on ''. |
2641
|
|
|
|
|
|
|
|
2642
|
|
|
|
|
|
|
sub _join_field_group_html { |
2643
|
0
|
|
|
0
|
|
|
my ($self, $defin, $ra_tag_html) = @_; |
2644
|
|
|
|
|
|
|
|
2645
|
|
|
|
|
|
|
# First, see if definition wants a list returned. |
2646
|
|
|
|
|
|
|
|
2647
|
0
|
0
|
|
|
|
|
$defin->fetch_value( $FKEY_LIST ) and return( $ra_tag_html ); |
2648
|
|
|
|
|
|
|
|
2649
|
|
|
|
|
|
|
# Second, see if definition wants linebreak-delimited fields. |
2650
|
|
|
|
|
|
|
|
2651
|
0
|
|
|
|
|
|
$defin->fetch_value( $FKEY_LINEBREAK ) and |
2652
|
0
|
0
|
|
|
|
|
return( join( ' ', @{$ra_tag_html} ) ); |
2653
|
|
|
|
|
|
|
|
2654
|
|
|
|
|
|
|
# Third, see if definition wants fields returned in an HTML table. |
2655
|
|
|
|
|
|
|
|
2656
|
0
|
|
|
|
|
|
my $cols = $defin->fetch_value( $FKEY_TABLE_COLS ); # 3 lines chg 2.01 |
2657
|
0
|
|
|
|
|
|
my $rows = $defin->fetch_value( $FKEY_TABLE_ROWS ); |
2658
|
0
|
|
|
|
|
|
my $acr_first = $defin->fetch_value( $FKEY_TABLE_ACRF ); |
2659
|
0
|
0
|
0
|
|
|
|
if( $cols or $rows ) { |
2660
|
0
|
|
|
|
|
|
return( $self->make_table_from_list( $ra_tag_html, |
2661
|
|
|
|
|
|
|
$cols, $rows, $acr_first ) ); |
2662
|
|
|
|
|
|
|
} |
2663
|
|
|
|
|
|
|
|
2664
|
|
|
|
|
|
|
# If none of the above, then return fields concatenated as is. |
2665
|
|
|
|
|
|
|
|
2666
|
0
|
|
|
|
|
|
return( join( '', @{$ra_tag_html} ) ); |
|
0
|
|
|
|
|
|
|
2667
|
|
|
|
|
|
|
} |
2668
|
|
|
|
|
|
|
|
2669
|
|
|
|
|
|
|
###################################################################### |
2670
|
|
|
|
|
|
|
|
2671
|
|
|
|
|
|
|
1; |
2672
|
|
|
|
|
|
|
__END__ |