1HTML::FillInForm(3) User Contributed Perl Documentation HTML::FillInForm(3)
2
3
4
6 HTML::FillInForm - Populates HTML Forms with data.
7
9 This module fills in an HTML form with data from a Perl data structure,
10 allowing you to keep the HTML and Perl separate.
11
12 Here are two common use cases:
13
14 1. A user submits an HTML form without filling out a required field.
15 You want to redisplay the form with all the previous data in it, to
16 make it easy for the user to see and correct the error.
17
18 2. You have just retrieved a record from a database and need to display
19 it in an HTML form.
20
22 Fill HTML form with data.
23
24 $output = HTML::FillInForm->fill( \$html, $q );
25 $output = HTML::FillInForm->fill( \@html, [$q1,$q2] );
26 $output = HTML::FillInForm->fill( \*HTML, \%data );
27 $output = HTML::FillInForm->fill( 't.html', [\%data1,%data2] );
28
29 The HTML can be provided as a scalarref, arrayref, filehandle or file.
30 The data can come from one or more hashrefs, or objects which support a
31 param() method, like CGI.pm, Apache::Request, etc.
32
34 The basic syntax is seen above the Synopsis. There are a few additional
35 options.
36
37 Options
38 target => 'form1'
39
40 Suppose you have multiple forms in a html file and only want to fill in
41 one.
42
43 $output = HTML::FillInForm->fill(\$html, $q, target => 'form1');
44
45 This will fill in only the form inside
46
47 <FORM name="form1"> ... </FORM>
48
49 fill_password => 0
50
51 Passwords are filled in by default. To disable:
52
53 fill_password => 0
54
55 ignore_fields => []
56
57 To disable the filling of some fields:
58
59 ignore_fields => ['prev','next']
60
61 disable_fields => []
62
63 To disable fields from being edited:
64
65 disable_fields => [ 'uid', 'gid' ]
66
67 File Upload fields
68 File upload fields cannot be supported directly. Workarounds include
69 asking the user to re-attach any file uploads or fancy server-side
70 storage and referencing. You are on your own.
71
72 Clearing Fields
73 Fields are cleared if you set their value to an empty string or empty
74 arrayref but not undef:
75
76 # this will leave the form element foo untouched
77 HTML::FillInForm->fill(\$html, { foo => undef });
78
79 # this will set clear the form element foo
80 HTML::FillInForm->fill(\$html, { foo => "" });
81
82 It has been suggested to add a option to change the behavior so that
83 undef values will clear the form elements. Patches welcome.
84
86 You probably need to read no further. The remaining docs concern the
87 1.x era syntax, which is still supported.
88
89 new
90 Call "new()" to create a new FillInForm object:
91
92 $fif = HTML::FillInForm->new;
93 $fif->fill(...);
94
95 In theory, there is a slight performance benefit to calling "new()"
96 before "fill()" if you make multiple calls to "fill()" before you
97 destroy the object. Benchmark before optimizing.
98
99 fill ( old syntax )
100 Instead of having your HTML and data types auto-detected, you can
101 declare them explicitly in your call to "fill()":
102
103 HTML source options:
104
105 arrayref => @html
106 scalarref => $html
107 file => \*HTML
108 file => 't.html'
109
110 Fill Data options:
111
112 fobject => $data_obj # with param() method
113 fdat => \%data
114
115 Additional methods are also available:
116
117 fill_file(\*HTML,...);
118 fill_file('t.html',...);
119 fill_arrayref(\@html,...);
120 fill_scalarref(\$html,...);
121
123 Apache::PageKit
124 To use HTML::FillInForm in Apache::PageKit is easy. It is
125 automatically called for any page that includes a <form> tag. It can
126 be turned on or off by using the "fill_in_form" configuration option.
127
128 Apache::ASP v2.09 and above
129 HTML::FillInForm is now integrated with Apache::ASP. To activate, use
130
131 PerlSetVar FormFill 1
132 $Response->{FormFill} = 1
133
134 HTML::Mason
135 Using HTML::FillInForm from HTML::Mason is covered in the FAQ on the
136 masonhq.com website at
137 http://www.masonhq.com/?FAQ:HTTPAndHTML#h-how_can_i_populate_form_values_automatically_
138 <http://www.masonhq.com/?FAQ:HTTPAndHTML#h-
139 how_can_i_populate_form_values_automatically_>
140
142 This documentation describes HTML::FillInForm module version 2.00
143
145 Note that you might want to think about caching issues if you have
146 password fields on your page. There is a discussion of this issue at
147
148 http://www.perlmonks.org/index.pl?node_id=70482
149
150 In summary, some browsers will cache the output of CGI scripts, and you
151 can control this by setting the Expires header. For example, use
152 "-expires" in CGI.pm or set "browser_cache" to no in Config.xml file of
153 Apache::PageKit.
154
156 Kato Atsushi has translated these docs into Japanese, available from
157
158 http://perldoc.jp
159
161 Please submit any bug reports to tjmather@maxmind.com.
162
164 Requires Perl 5.005 and HTML::Parser version 3.26.
165
166 I wrote this module because I wanted to be able to insert CGI data into
167 HTML forms, but without combining the HTML and Perl code. CGI.pm and
168 Embperl allow you so insert CGI data into forms, but require that you
169 mix HTML with Perl.
170
171 There is a nice review of the module available here:
172 <http://www.perlmonks.org/index.pl?node_id=274534>
173
175 (c) 2005 TJ Mather, tjmather@maxmind.com, <http://www.maxmind.com/>
176
177 All rights reserved. This package is free software; you can
178 redistribute it and/or modify it under the same terms as Perl itself.
179
181 HTML::Parser, Data::FormValidator, HTML::Template, Apache::PageKit
182
184 Fixes, Bug Reports, Docs have been generously provided by:
185
186 Tatsuhiko Miyagawa Joseph Yanni
187 Boris Zentner Philip Mak
188 Dave Rolsky Jost Krieger
189 Patrick Michael Kane Gabriel Burka
190 Ade Olonoh Bill Moseley
191 Tom Lancaster James Tolley
192 Martin H Sluka Dan Kubb
193 Mark Stosberg Alexander Hartmaier
194 Jonathan Swartz Paul Miller
195 Trevor Schellhorn Anthony Ettinger
196 Jim Miner Simon P. Ditner
197 Paul Lindner Michael Peters
198 Maurice Aubrey Trevor Schellhorn
199 Andrew Creer
200
201 Thanks!
202
203
204
205perl v5.12.0 2007-09-12 HTML::FillInForm(3)