
HTML::Template::Associate::FormField
- CGI Form for using by HTML::Template is generated. - HTML::Template::Associate FormField plugin.

use CGI;
use HTML::Template;
use HTML::Template::Associate::FormField;
## The form field setup. ( CGI.pm like )
my %formfields= (
StartForm=> { type=> 'opt_form' },
Name => { type=> 'textfield', size=> 30, maxlength=> 100 },
Email => { type=> 'textfield', size=> 50, maxlength=> 200 },
Sex => { type=> 'select', values=> [0, 1, 2],
labels=> { 0=> 'please select !!', 1=> 'man', 2=> 'gal' } },
ID => { type=> 'textfield', size=> 15, maxlength=> 15 },
Passwd=> { type=> 'password', size=> 15, maxlength=> 15,
default=> "", override=> 1 },
submit=> { type=> 'submit', value=> ' Please push !! ' },
);
## The template.
my $example_template= <<END_OF_TEMPLATE;
<html>
<head><title>Exsample template</title></head>
<body>
<h1>Exsample CGI Form</h1>
<form <tmpl_var name="__StartForm__">>
<table>
<tr><td>Name </td><td> <tmpl_var name="__NAME__"> </td></tr>
<tr><td>E-mail </td><td> <tmpl_var name="__EMAIL__"> </td></tr>
<tr><td>Sex </td><td> <tmpl_var name="__SEX__"> </td></tr>
<tr><td>ID </td><td> <tmpl_var name="__ID__"> </td></tr>
<tr><td>PASSWORD </td><td> <tmpl_var name="__PASSWD__"> </td></tr>
</table>
<tmpl_var name="__SUBMIT__">
</form>
</body>
</html>
END_OF_TEMPLATE
## The code.
my $cgi = CGI->new;
# Give CGI object and definition of field EEE
my $form= HTML::Template::Associate::FormField->new($cgi, \%formfields);
# Give ... ::Form Field object to associate
my $tp = HTML::Template->new(
scalarref=> \$example_template,
associate=> [$form],
);
# And output your screen
print $cgi->header, $tp->output;
or, a way to use not give associateEEE
my $cgi = CGI->new;
my $form= HTML::Template::Associate::FormField->new($cgi, \%formfields);
my $tp = HTML::Template->new(scalarref=> \$example_template);
# set up the parameter directly
$tp->param('__StartForm__', $form->param('StartForm'));
$tp->param('__NAME__', $form->param('Name'));
$tp->param('__EMAIL__', $form->param('Email'));
$tp->param('__SEX__', $form->param('Sex'));
$tp->param('__ID__', $form->param('ID'));
$tp->param('__PASSWD__', $form->param('Passwd'));
$tp->param('__SUBMIT__', $form->param('submit'));
print $cgi->header, $tp->output;
# If you move it as a plug-in of HTML::Template::Associate.
# * The code is an offer from "Alex Pavlovic" who is the author of HTML::Template::Associate.
use HTML::Template;
use HTML::Template::Associate;
my $associate = HTML::Template::Associate->new ({
target => 'FormField',
cgi => $cgi,
form_fields => \%formfields
});
my $template= HTML::Template->new (
scalarref=> \$example_template,
associate=> [ $associate ],
);
print $cgi->header, $template->output;

This is Form Field object using bridge associate option of HTML::Template. Fill in the Form Field which made from object follow the template. If the Form Field data which was input at the previous screen exist, it is easy to make code, because process (CGI pm dependense) of fill in Form is automatic.
startform , start_multipart_form , endform , textfield , filefield , password_field , textarea , checkbox , radio_group , popup_menu , optgroup , scrolling_list , image_button , defaults , button , reset
form ... other name of startform. (%)
start_upload_form ... other name of start_multipart_form. (%)
upload_form ... other name of start_multipart_form. (%)
opt_form ... return only a part of attribute of startform.
opt_multipart_form ... return only a part of attribute of start_multipart_form.
opt_upload_form ... other name of opt_multipart_form.
hidden_field ... return all of no indication Field which is seting up.
hidden ... other name of hidden_field
text ... other name of textfield.
file ... other name of filefield.
password ... other name of password_field.
radio ... other name of radio_group.
select ... other name of popup_menu.
image ... other name of image_button.
(%) In case of no indication Field was set up , connect the no indication Field and return the value.
$cgi->param('Baz', 'Hello!!');
my %formfields= ( 'Foo'=> { alias=> 'Baz', type=> 'textfield' } );

Constructor
$form= HTML::Template::Associate::FormField->new($cgi, \%formfields);
Constructor for HTML::Template::Associate.
Set up or refer to definition parameter of CGI Form.
(All keys which was able to get by this are enclosed by '__')
$form->param;
$form->param('Foo');
or
$form->param('__FOO__');
Access to object which control no indication Field.
$form->hidden->set('Foo', 'Hoge');
$form->hidden->get;
$form->hidden->get('Foo');
$form->hidden->unset('Foo');
$form->hidden->exists ? 'true': 'false';
$form->hidden->clear;
Export no indication Field, object.
my %hash = ( 'Foo'=> 'Form Field !!' );
$hidden = $form->hidden_out(\%hash);
$hidden->set('Baz', 'Hoge');
$hidden->get;
$hidden->unset('Baz');
$tp= HTML::Template->new( ..... );
$tp->param('HIDDEN_FIELD', $hidden->get);

In case of errors in the definition of Form field, return this error message instead of Form field.
There is no designation of type in definition Form field.
Errors in definition form of type.

When you call a function start_form without an action attribute by old CGI module, you might find a caution "Use of uninitialized value". In this case, let's upgrade to the latest CGI module.

HTML::Template, CGI

Generously contributed to English translation by:
Ayumi Ohno
Special Thanks!

Masatoshi Mizuno <lushe@cpan.org>

Copyright (C) 2004-2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.