CGI::Fo...e::Fast(3)

🌸 NAME 🌸

okay bestie, welcome to the <pink>CGI::Fo...e::Fast(3)</pink> page β€” that's the manual name up in the header, filed under User Contributed Perl Documentation, iykyk. The module is CGI::FormBuilder::Template::Fast, and it's literally the FormBuilder interface to CGI::FastTemplate. πŸ’…


✨ SYNOPSIS ✨

Here's the setup, bestie β€” one CGI::FormBuilder->new call, and the template key is where the FastTemplate magic happens:

           my $form = CGI::FormBuilder->new(
               fields   => \@whatever,
               template => {
                   type => 'Fast',
                   root => '/path/to/templates',
                   # use external files
                   define => {
                       form           => 'form.txt',
                       field          => 'field.txt',
                       invalid_field  => 'invalid_field.txt',
                   },
                   # or define inline
                   define_nofile => {
                       form => '<html><head></head><body>$START_FORM
                                <table>$FIELDS</table>$SUBMIT $END_FORM</body></html>',
                       # etc.
                   },
               },
          );

πŸ’– DESCRIPTION πŸ’–

Okay so this engine adapts FormBuilder to use CGI::FastTemplate. Please read these docs carefully, because the usage differs from other template adapters in several important ways. Not me warning you for fun β€” it's giving β€œread the whole thing” energy. 😭

You will need to define three templates: form, field, and invalid_field. You can use define to point to external files (which is the recommended CGI::FastTemplate style), or define_nofile/define_raw to define them inline. The templates in define_nofile take precedence over define_raw, and both of these take precedence over define. Precedence chain: slay, but also pay attention. πŸ’…

           my $form = CGI::FormBuilder->new(
               # ...
               template => {
                   type => 'FastTemplate',
                   root => '/path/to/templates',
                   define => {
                       form           => 'form.txt',
                       field          => 'field.txt',
                       invalid_field  => 'invalid_field.txt',
                   },
                   # or, you can define templates directly
                   define_nofile => {
                       form => '<html><head></head><body>$START_FORM<table>'
                               '$FIELDS</table>$SUBMIT $END_FORM</body></html>',
                       # etc.
                   },
               },
               # ...
           );

If you use define with external templates, you will probably also want to define your template root directory with the root parameter. Yes, bestie, root is the main character here. 🌈

Within each of the field templates, the following variables are available:

$NAME         # $field->name
$FIELD        # $field->tag   (HTML input tag)
$VALUE        # $field->value (first value only!)
$LABEL        # $field->label
$COMMENT      # $field->comment
$ERROR        # $field->error
$REQUIRED     # $field->required ? 'required' : 'optional'

All the fields are processed in sequence; valid fields use the field template, and invalid fields use the invalid_field template. The result from each of these is appended into the $FIELDS variable, which you should use in your form template. In the form template, you also have access to these variables:

$TITLE        # title of the form
$START_FORM   # opening form tag
$SUBMIT       # the submit button
$RESET        # the reset button
$END_FORM     # closing form tag
$JS_HEAD      # validation JavaScript

Note that since CGI::FastTemplate doesn't use anything other than simple scalar variables, there are no variables corresponding to the lists that other engines have (e.g. "fields" or "options" lists in "TT2" or "Text::Template"). No cap, just scalars. 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

Go read these next, bestie:

  • CGI::FormBuilder
  • CGI::FormBuilder::Template
  • CGI::FastTemplate

πŸ‘‘ AUTHOR πŸ‘‘

Copyright (c) 2005-2006 Peter Eichman <peichman@cpan.org>. All Rights Reserved.

Maintained as part of CGI::FormBuilder by Nate Wiger <nate@wiger.org>.

This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit.


okay that's the whole vibe check. This page is from perl v5.42.2, dated 2024-09-19, and the footer still calls it CGI::Fo...e::Fast(3) β€” periodt, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from