1CGI::FormBuilder::TemplUasteer::CToTn2t(r3i)buted Perl DCoGcIu:m:eFnotramtBiuoinlder::Template::TT2(3)
2
3
4

NAME

6       CGI::FormBuilder::Template::TT2 - FormBuilder interface to Template
7       Toolkit
8

SYNOPSIS

10           my $form = CGI::FormBuilder->new(
11                           fields   => \@fields,
12                           template => {
13                               type => 'TT2',
14                               template => 'form.tmpl',
15                               variable => 'form',
16                           }
17                      );
18

DESCRIPTION

20       This engine adapts FormBuilder to use "Template Toolkit".  To do so,
21       specify the "template" option as a hashref which includes the "type"
22       option set to "TT2" and the "template" option set to the name of the
23       template you want processed. You can also add "variable" as an option
24       (among others) to denote the variable name that you want the form data
25       to be referenced by:
26
27           my $form = CGI::FormBuilder->new(
28                           fields => \@fields,
29                           template => {
30                               type => 'TT2',
31                               template => 'userinfo.tmpl',
32                               variable => 'form',
33                           }
34                      );
35
36       The following methods are provided (usually only used internally):
37
38       engine
39
40       Returns a reference to the "Template" object
41
42       prepare
43
44       Returns a hash of all the fields ready to be rendered.
45
46       render
47
48       Uses the prepared hash and expands the template, returning a string of
49       HTML.
50

TEMPLATES

52       The template might look something like this:
53
54           <html>
55           <head>
56             <title>[% form.title %]</title>
57             [% form.jshead %]
58           </head>
59           <body>
60             [% form.start %]
61             <table>
62               [% FOREACH field = form.fields %]
63               <tr valign="top">
64                 <td>
65                   [% field.required
66                         ? "<b>$field.label</b>"
67                         : field.label
68                   %]
69                 </td>
70                 <td>
71                   [% IF field.invalid %]
72                   Missing or invalid entry, please try again.
73               <br/>
74               [% END %]
75
76               [% field.field %]
77             </td>
78           </tr>
79               [% END %]
80               <tr>
81                 <td colspan="2" align="center">
82                   [% form.submit %] [% form.reset %]
83                 </td>
84               </tr>
85             </table>
86             [% form.end %]
87           </body>
88           </html>
89
90       By default, the Template Toolkit makes all the form and field informa‐
91       tion accessible through simple variables.
92
93           [% jshead %]  -  JavaScript to stick in <head>
94           [% title  %]  -  The <title> of the HTML form
95           [% start  %]  -  Opening <form> tag and internal fields
96           [% submit %]  -  The submit button(s)
97           [% reset  %]  -  The reset button
98           [% end    %]  -  Closing </form> tag
99           [% fields %]  -  List of fields
100           [% field  %]  -  Hash of fields (for lookup by name)
101
102       You can specify the "variable" option to have all these variables
103       accessible under a certain namespace.  For example:
104
105           my $form = CGI::FormBuilder->new(
106               fields => \@fields,
107               template => {
108                    type => 'TT2',
109                    template => 'form.tmpl',
110                    variable => 'form'
111               },
112           );
113
114       With "variable" set to "form" the variables are accessible as:
115
116           [% form.jshead %]
117           [% form.start  %]
118           etc.
119
120       You can access individual fields via the "field" variable.
121
122           For a field named...  The field data is in...
123           --------------------  -----------------------
124           job                   [% form.field.job   %]
125           size                  [% form.field.size  %]
126           email                 [% form.field.email %]
127
128       Each field contains various elements.  For example:
129
130           [% myfield = form.field.email %]
131
132           [% myfield.label    %]  # text label
133           [% myfield.field    %]  # field input tag
134           [% myfield.value    %]  # first value
135           [% myfield.values   %]  # list of all values
136           [% myfield.option   %]  # first value
137           [% myfield.options  %]  # list of all values
138           [% myfield.required %]  # required flag
139           [% myfield.invalid  %]  # invalid flag
140
141       The "fields" variable contains a list of all the fields in the form.
142       To iterate through all the fields in order, you could do something like
143       this:
144
145           [% FOREACH field = form.fields %]
146           <tr>
147            <td>[% field.label %]</td> <td>[% field.field %]</td>
148           </tr>
149           [% END %]
150
151       If you want to customise any of the Template Toolkit options, you can
152       set the "engine" option to contain a reference to an existing "Tem‐
153       plate" object or hash reference of options which are passed to the
154       "Template" constructor.  You can also set the "data" item to define any
155       additional variables you want accesible when the template is processed.
156
157           my $form = CGI::FormBuilder->new(
158               fields => \@fields,
159               template => {
160                    type => 'TT2',
161                    template => 'form.tmpl',
162                    variable => 'form',
163                    engine   => {
164                         INCLUDE_PATH => '/usr/local/tt2/templates',
165                    },
166                    data => {
167                         version => 1.23,
168                         author  => 'Fred Smith',
169                    },
170               },
171           );
172
173       For further details on using the Template Toolkit, see "Template" or
174       <http://www.template-toolkit.org>
175

SEE ALSO

177       CGI::FormBuilder, CGI::FormBuilder::Template, Template
178

REVISION

180       $Id: TT2.pm 100 2007-03-02 18:13:13Z nwiger $
181

AUTHOR

183       Copyright (c) 2000-2006 Nate Wiger <nate@wiger.org>. All Rights
184       Reserved.
185
186       Template Tookit support is largely due to a huge patch from Andy Ward‐
187       ley.
188
189       This module is free software; you may copy this under the terms of the
190       GNU General Public License, or the Artistic License, copies of which
191       should have accompanied your Perl kit.
192
193
194
195perl v5.8.8                       2007-03-02CGI::FormBuilder::Template::TT2(3)
Impressum