HTML::FillInForm(3) User Contributed Perl Documentation HTML::FillInForm(3)NAMEHTML::FillInForm - Populates HTML Forms with data.
DESCRIPTION
This module automatically inserts data from a previous HTML form into
the HTML input, textarea, radio buttons, checkboxes and select tags.
It is a subclass of HTML::Parser and uses it to parse the HTML and
insert the values into the form tags.
One useful application is after a user submits an HTML form without
filling out a required field. HTML::FillInForm can be used to redis-
play the HTML form with all the form elements containing the submitted
info.
SYNOPSIS
This examples fills data into a HTML form stored in $htmlForm from CGI
parameters that are stored in $q. For example, it will set the value
of any "name" textfield to "John Smith".
my $q = new CGI;
$q->param("name","John Smith");
my $fif = new HTML::FillInForm;
my $output = $fif->fill(scalarref => \$html,
fobject => $q);
Note CGI.pm is not required - see using fdat below. Also you can use a
CGI.pm-like object such as Apache::Request.
METHODS
new Call "new()" to create a new FillInForm object:
$fif = new HTML::FillInForm;
fill
To fill in a HTML form contained in a scalar $html:
$output = $fif->fill(scalarref => \$html,
fobject => $q);
Returns filled in HTML form contained in $html with data from $q.
$q is required to have a "param()" method that works like CGI's
"param()".
$output = $fif->fill(scalarref => \$html,
fobject => [$q1, $q2]);
As of 1.04 the object passed does not need to return all its keys
with a empty param() call.
Note that you can pass multiple objects as an array reference.
$output = $fif->fill(scalarref => \$html,
fdat => \%fdat);
Returns filled in HTML form contained in $html with data from
%fdat. To pass multiple values using %fdat use an array reference.
Alternately you can use
$output = $fif->fill(arrayref => \@array_of_lines,
fobject => $q);
and
$output = $fif->fill(file => 'form.tmpl',
fobject => $q);
Suppose you have multiple forms in a html and among them there is
only one form you want to fill in, specify target.
$output = $fif->fill(scalarref => \$html,
fobject => $q,
target => 'form1');
This will fill in only the form inside
<FORM name="form1"> ... </FORM>
Note that this method fills in password fields by default. To dis-
able, pass
fill_password => 0
To disable the filling of some fields, use the "ignore_fields"
option:
$output = $fif->fill(scalarref => \$html,
fobject => $q,
ignore_fields => ['prev','next']);
Note that this module does not clear fields if you set the value to
undef. It will clear fields if you set the value to an empty array
or an empty string. For example:
# this will leave the form element foo untouched
$output = $fif->fill(scalarref => \$html,
fdat => { foo => undef });
# this will set clear the form element foo
$output = $fif->fill(scalarref => \$html,
fdat => { foo => "" });
It has been suggested to add a option to the new constructer to
change the behavior so that undef values will clear the form ele-
ments. Patches welcome.
CALLING FROM OTHER MODULES
Apache::PageKit
To use HTML::FillInForm in Apache::PageKit is easy. It is automati-
cally called for any page that includes a <form> tag. It can be turned
on or off by using the "fill_in_form" configuration option.
Apache::ASP v2.09 and above
HTML::FillInForm is now integrated with Apache::ASP. To activate, use
PerlSetVar FormFill 1
$Response->{FormFill} = 1
HTML::Mason
Using HTML::FillInForm from HTML::Mason is covered in the FAQ on the
masonhq.com website at <http://www.masonhq.com/?FAQ:HTTPAnd-
HTML#h-how_can_i_populate_form_values_automatically_>
VERSION
This documentation describes HTML::FillInForm module version 1.06.
SECURITY
Note that you might want to think about caching issues if you have
password fields on your page. There is a discussion of this issue at
http://www.perlmonks.org/index.pl?node_id=70482
In summary, some browsers will cache the output of CGI scripts, and you
can control this by setting the Expires header. For example, use
"-expires" in CGI.pm or set "browser_cache" to no in Config.xml file of
Apache::PageKit.
TRANSLATION
Kato Atsushi has translated these docs into Japanese, available from
http://perldoc.jp
BUGS
Please submit any bug reports to tjmather@maxmind.com.
NOTES
Requires Perl 5.005 and HTML::Parser version 3.26.
I wrote this module because I wanted to be able to insert CGI data into
HTML forms, but without combining the HTML and Perl code. CGI.pm and
Embperl allow you so insert CGI data into forms, but require that you
mix HTML with Perl.
There is a nice review of the module available here: <http://www.perl-
monks.org/index.pl?node_id=274534>
AUTHOR
(c) 2005 TJ Mather, tjmather@maxmind.com, <http://www.maxmind.com/>
All rights reserved. This package is free software; you can redis-
tribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
HTML::Parser, Data::FormValidator, HTML::Template, Apache::PageKit
CREDITS
Fixes, Bug Reports, Docs have been generously provided by:
Tatsuhiko Miyagawa
Boris Zentner
Dave Rolsky
Patrick Michael Kane
Ade Olonoh
Tom Lancaster
Martin H Sluka
Mark Stosberg
Jonathan Swartz
Trevor Schellhorn
Jim Miner
Paul Lindner
Maurice Aubrey
Andrew Creer
Joseph Yanni
Philip Mak
Jost Krieger
Gabriel Burka
Bill Moseley
James Tolley
Dan Kubb
Thanks!
perl v5.8.8 2005-10-13 HTML::FillInForm(3)