View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Masatoshi Mizuno > HTML-Template-Associate-FormField > HTML::Template::Associate::FormField



Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  



  - 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. ( 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;
 <head><title>Exsample template</title></head>
 <h1>Exsample CGI Form</h1>
 <form <tmpl_var name="__StartForm__">>
 <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>
 <tmpl_var name="__SUBMIT__">

 ## The code.
 my $cgi = CGI->new;
 # Give CGI object and definition of field EEE
 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 associateEEE

 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.

Form Field Setup




  1. Accept CGI object or HASH reference to the first parameter.
  2. Accept definition of CGI Form (HASH reference) to the second parameter.

    $form= HTML::Template::Associate::FormField->new($cgi, \%formfields);


Constructor for HTML::Template::Associate.

param, params

Set up or refer to definition parameter of CGI Form.


Access to object which control no indication Field.


Export no indication Field, object.


In case of errors in the definition of Form field, return this error message instead of Form field.


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 <>


Copyright (C) 2004-2007 by Bee Flag, Corp. <>, 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.

syntax highlighting: