The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CGI::Form::Table - create a table of form inputs

VERSION

version 0.10

 $Id: Table.pm,v 1.9 2004/10/20 14:24:20 rjbs Exp $

SYNOPSIS

 use CGI::Form::Table;

 my $form = CGI::Form::Table->new(
   prefix  => 'employee',
   columns => [qw(lname fname job age)]
 );

 print $form->as_html;
 print $form->javascript;

DESCRIPTION

This module simplifies the creation of an HTML table containing form inputs. The table can be extended to include extra rows, and these rows can be removed. Each has a unique name, and on form submission the inputs are effectively serialized.

CGI::Form::Table::Reader will use the CGI module to produce a data structure based on the parameters submitted by a form of this type.

METHODS

CGI::Form::Table->new(%arg)

This method constructs a new form. The only required arguments are columns, which names the columns that will be in the form table, and prefix, which gives the unique prefix for input fields.

If given, initial_rows specifies how many rows should initially be in the form.

Another argument, column_content, may be passed. It must contain a hashref, with entries providing subs to produce initial content. The subs are passed the form object, the row number, and the name of the column. For example, to add a reminder of the current row in the middle of each row, you might create a form like this:

 my $form = CGI::Form::Table->new(
   prefix  => 'simpleform',
   columns => [qw(one two reminder three four)],
   column_content => {
     reminder => sub { $_[1] }
   }
 );

This can be useful for forms that require SELECT elements or other complicated parts. (The JavaScript will just copy the column value when new rows are added, updating the name attribute.)

CGI::Form::Table->as_html

This returns HTML representing the form object. JavaScript is required to make the form expandible/shrinkable; see the javascript method. ("SEE ALSO")

javascript

This method returns JavaScript that will make the handlers for the HTML buttons work. This code has been (poorly) tested in Firefox, MSIE, and WebKit-based browsers.

SEE ALSO

AUTHOR

Ricardo SIGNES, <rjbs@cpan.org>

BUGS

Please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT

Copyright 2004 Ricardo SIGNES, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.