1HTML::FillInForm(3)   User Contributed Perl Documentation  HTML::FillInForm(3)
2
3
4

NAME

6       HTML::FillInForm - Populates HTML Forms with data.
7

VERSION

9       version 2.22
10

SYNOPSIS

12       Fill HTML form with data.
13
14         $output = HTML::FillInForm->fill( \$html,   $q );
15         $output = HTML::FillInForm->fill( \@html,   [$q1,$q2] );
16         $output = HTML::FillInForm->fill( \*HTML,   \%data );
17         $output = HTML::FillInForm->fill( 't.html', [\%data1,%data2] );
18
19       The HTML can be provided as a scalarref, arrayref, filehandle or file.
20       The data can come from one or more hashrefs, or objects which support a
21       param() method, like CGI.pm, Apache::Request, etc.
22

DESCRIPTION

24       This module fills in an HTML form with data from a Perl data structure,
25       allowing you to keep the HTML and Perl separate.
26
27       Here are two common use cases:
28
29       1. A user submits an HTML form without filling out a required field.
30       You want to redisplay the form with all the previous data in it, to
31       make it easy for the user to see and correct the error.
32
33       2. You have just retrieved a record from a database and need to display
34       it in an HTML form.
35

fill

37       The basic syntax is seen above the Synopsis. There are a few additional
38       options.
39
40   Options
41       target => 'form1'
42
43       Suppose you have multiple forms in a html file and only want to fill in
44       one.
45
46         $output = HTML::FillInForm->fill(\$html, $q, target => 'form1');
47
48       This will fill in only the form inside
49
50         <FORM name="form1"> ... </FORM>
51
52       fill_password => 0
53
54       Passwords are filled in by default. To disable:
55
56         fill_password => 0
57
58       ignore_fields => []
59
60       To disable the filling of some fields:
61
62           ignore_fields => ['prev','next']
63
64       disable_fields => []
65
66       To disable fields from being edited:
67
68           disable_fields => [ 'uid', 'gid' ]
69
70       invalid_fields => []
71
72       To mark fields as being invalid (CSS class set to "invalid" or whatever
73       you set invalid_class to):
74
75           invalid_fields => [ 'uid', 'gid' ]
76
77       invalid_class => "invalid"
78
79       The CSS class which will be used to mark fields invalid.  Defaults to
80       "invalid".
81
82       clear_absent_checkboxes => 0
83
84       Absent fields are not cleared or in any way changed. This is not what
85       you want when you deal with checkboxes which are not sent by browser at
86       all when cleared by user.
87
88       To remove "checked" attribute from checkboxes and radio buttons and
89       attribute "selected" from options of select lists for which there's no
90       data:
91
92           clear_absent_checkboxes => 1
93
94   File Upload fields
95       File upload fields cannot be supported directly. Workarounds include
96       asking the user to re-attach any file uploads or fancy server-side
97       storage and referencing. You are on your own.
98
99   Clearing Fields
100       Fields are cleared if you set their value to an empty string or empty
101       arrayref but not undef:
102
103         # this will leave the form element foo untouched
104         HTML::FillInForm->fill(\$html, { foo => undef });
105
106         # this will set clear the form element foo
107         HTML::FillInForm->fill(\$html, { foo => "" });
108
109       It has been suggested to add a option to change the behavior so that
110       undef values will clear the form elements.  Patches welcome.
111
112       You can also use "clear_absent_checkboxes" option to clear checkboxes,
113       radio buttons and selects without corresponding keys in the data:
114
115           # this will set clear the form element foo (and all others except
116           # bar)
117           HTML::FillInForm->fill(\$html, { bar => 123 },
118               clear_absent_checkboxes => 1);
119

Old syntax

121       You probably need to read no further. The remaining docs concern the
122       1.x era syntax, which is still supported.
123
124   new
125       Call "new()" to create a new FillInForm object:
126
127         $fif = HTML::FillInForm->new;
128         $fif->fill(...);
129
130       In theory, there is a slight performance benefit to calling "new()"
131       before "fill()" if you make multiple calls to "fill()" before you
132       destroy the object. Benchmark before optimizing.
133
134   fill ( old syntax )
135       Instead of having your HTML and data types auto-detected, you can
136       declare them explicitly in your call to "fill()":
137
138       HTML source options:
139
140           arrayref  => @html
141           scalarref => $html
142           file      => \*HTML
143           file      => 't.html'
144
145       Fill Data options:
146
147           fobject   => $data_obj  # with param() method
148           fdat      => \%data
149
150       Additional methods are also available:
151
152           fill_file(\*HTML,...);
153           fill_file('t.html',...);
154           fill_arrayref(\@html,...);
155           fill_scalarref(\$html,...);
156

USING AN ALTERNATE PARSER

158       It's possible to use an alternate parser to HTML::Parser if the
159       alternate provides a sufficiently compatible interface. For example,
160       when a Pure Perl implementation of HTML::Parser appears, it could be
161       used for portability. The syntax is simply to provide a "parser_class"
162       to new();
163
164          HTML::FillInForm->new( parser_class => 'MyAlternate::Parser' );
165

CALLING FROM OTHER MODULES

167   Apache::PageKit
168       To use HTML::FillInForm in Apache::PageKit is easy.   It is
169       automatically called for any page that includes a <form> tag.  It can
170       be turned on or off by using the "fill_in_form" configuration option.
171
172   Apache::ASP v2.09 and above
173       HTML::FillInForm is now integrated with Apache::ASP.  To activate, use
174
175         PerlSetVar FormFill 1
176         $Response->{FormFill} = 1
177
178   HTML::Mason
179       Using HTML::FillInForm from HTML::Mason is covered in the FAQ on the
180       masonhq.com website at
181       <http://www.masonhq.com/?FAQ:HTTPAndHTML#h-how_can_i_populate_form_values_automatically_>
182

SECURITY

184       Note that you might want to think about caching issues if you have
185       password fields on your page.  There is a discussion of this issue at
186
187       http://www.perlmonks.org/index.pl?node_id=70482
188
189       In summary, some browsers will cache the output of CGI scripts, and you
190       can control this by setting the Expires header.  For example, use
191       "-expires" in CGI.pm or set "browser_cache" to no in Config.xml file of
192       Apache::PageKit.
193

TRANSLATION

195       Kato Atsushi has translated these docs into Japanese, available from
196
197       http://perldoc.jp
198

BUGS

200       Please submit any bug reports to tjmather@maxmind.com.
201

NOTES

203       Requires Perl 5.005 and HTML::Parser version 3.26.
204
205       I wrote this module because I wanted to be able to insert CGI data into
206       HTML forms, but without combining the HTML and Perl code.  CGI.pm and
207       Embperl allow you so insert CGI data into forms, but require that you
208       mix HTML with Perl.
209
210       There is a nice review of the module available here:
211       <http://www.perlmonks.org/index.pl?node_id=274534>
212

SEE ALSO

214       HTML::Parser, Data::FormValidator, HTML::Template, Apache::PageKit
215

CREDITS

217       Fixes, Bug Reports, Docs have been generously provided by:
218
219         Alex Kapranoff                Miika Pekkarinen
220         Michael Fisher                Sam Tregar
221         Tatsuhiko Miyagawa            Joseph Yanni
222         Boris Zentner                 Philip Mak
223         Dave Rolsky                   Jost Krieger
224         Patrick Michael Kane          Gabriel Burka
225         Ade Olonoh                    Bill Moseley
226         Tom Lancaster                 James Tolley
227         Martin H Sluka                Dan Kubb
228         Mark Stosberg                 Alexander Hartmaier
229         Jonathan Swartz               Paul Miller
230         Trevor Schellhorn             Anthony Ettinger
231         Jim Miner                     Simon P. Ditner
232         Paul Lindner                  Michael Peters
233         Maurice Aubrey                Trevor Schellhorn
234         Andrew Creer
235
236       Thanks!
237

AUTHOR

239       TJ Mather, tjmather@maxmind.com
240
242       This software is copyright (c) 2000 by TJ Mather, tjmather@maxmind.com.
243
244       This is free software; you can redistribute it and/or modify it under
245       the same terms as the Perl 5 programming language system itself.
246
247
248
249perl v5.34.0                      2022-01-21               HTML::FillInForm(3)
Impressum