CGI-FormBuilder-Template-HTC
view release on metacpan or search on metacpan
lib/CGI/FormBuilder/Template/HTC.pm view on Meta::CPAN
</td>
</tr>
[%/loop %]
<tr>
<td colspan="2" align="center">
[%= form.submit %] [%= form.reset %]
</td>
</tr>
</table>
[%= form.end %]
</body>
</html>
By default, all the form and field information are accessible through simple variables.
[%= jshead %] - JavaScript to stick in <head>
[%= title %] - The <title> of the HTML form
[%= start %] - Opening <form> tag and internal fields
[%= submit %] - The submit button(s)
[%= reset %] - The reset button
[%= end %] - Closing </form> tag
[%= fields %] - List of fields
[%= field %] - Hash of fields (for lookup by name)
You can specify the variable option to have all these variables
accessible under a certain namespace. For example:
my $form = CGI::FormBuilder->new(
fields => \@fields,
template => {
type => 'HTC',
filename => 'form.tmpl',
variable => 'form'
},
);
With variable set to form the variables are accessible as:
[%= form.jshead %]
[%= form.start %]
etc.
You can access individual fields via the field variable.
For a field named... The field data is in...
-------------------- -----------------------
job [%= form.field.job %]
size [%= form.field.size %]
email [%= form.field.email %]
Each field contains various elements. For example:
[%with form.field.email %]
[%= label %] # text label
[%= field %] # field input tag
[%= value %] # first value
[%= values %] # list of all values
[%= option %] # first value
[%= options %] # list of all values
[%= required %] # required flag
[%= invalid %] # invalid flag
[%/with %]
The fields variable contains a list of all the fields in the form.
To iterate through all the fields in order, you could do something like this:
[%loop form.fields %]
<tr>
<td>[%= label %]</td> <td>[%= field %]</td>
</tr>
[%/loop %]
If you want to customise any of the HTC options, you can
add options to the C<template> option. You can also set the data
item to define any additional
variables you want accesible when the template is processed.
my $form = CGI::FormBuilder->new(
fields => \@fields,
template => {
type => 'HTC',
filename => 'form.tmpl',
variable => 'form',
# other HTC options
cache_dir => '/path/to/cachedir',
},
data => {
version => 1.23,
author => 'Fred Smith',
},
);
For further details on using the Template Toolkit, see
=head1 SEE ALSO
=over 4
=item L<CGI::FormBuilder>
=item L<CGI::FormBuilder::Template::TT2>
=item L<CGI::FormBuilder::Template::HTML>
=item L<HTML::Template::Compiled>
=back
=head1 AUTHOR
Tina Mueller
=head1 CREDITS
Nate Wiger, who is the author of L<CGI::FormBuilder>. I copied more or less
the whole documentation and some of the tests.
pfuschi from perl-community.de for the idae
( run in 1.039 second using v1.01-cache-2.11-cpan-ceb78f64989 )