NAME
HTML::FormHandler::Manual::Templates - using templates
SYNOPSIS
Documentation on templates to use with HTML::FormHandler
In progress...
Using templates
There are lots of different ways to set up templates. One way is to create a 'widget' directory, and store template snippets there.
You can use the default 'widget' for the field class, or set the 'widget' for the field in your form:
fields => [
my_special_field => {
type => 'Text',
widget => 'my_special_widget',
},
my_second_field => {
type => 'Text',
widget => 'yet_another_widget',
},
]
And include them in a generic template:
[% PROCESS widget/form_start.tt %]
[% FOREACH f IN form.sorted_fields %]
[% PROCESS widget/${f.widget}.tt %]
[% END %]
[% PROCESS widget/form_end.tt %]
Sample templates
Text input field with error class on div & error messages
<div class="[% f.css_class %] [% IF f.has_errors %]error_fld[% END %]">
[% IF f.has_errors %]
[% FOR error IN f.errors %]
<p><span class="error" id="error">[% error %] </span></p>
[% END %]
[% END %]
<label class="label" for="[% f.name %]">[% f.label %]</label>
<input type="text" name="[% f.name %]" id="[% f.name %]" value="[% f.fif %]">
</div>
Select field
Single select:
<label class="label" for="[% f.name %]">[% f.label %]</label>
<select name="[% f.name %]">
[% FOR option IN f.options %]
<option value="[% option.value %]"
[% IF option.value == f.fif %]
selected="selected"
[% END %]>
[% option.label %]</option>
[% END %]
</select>
Multiple select:
<label class="label" for="[% f.name %]">[% f.label || f.name %]</label>
<select name="[% f.name %]" multiple="multiple" size="5">
[% FOR option IN f.options %]
<option value="[% option.value %]"
[% FOREACH optval IN f.value %]
[% IF optval == option.value %]
selected="selected"
[% END %]
[% END %]>
[% option.label %]</option>
[% END %]
</select>
Checkbox
<input type="checkbox" name="[% f.name %]" value="1"
[% IF f.fif == 1 %] checked="checked"[% END %] />
AUTHOR
Gerda Shank, gshank@cpan.org
COPYRIGHT
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.