CGI-EZForm
view release on metacpan or search on metacpan
which does everything.
=back
Here's a sample script to demonstrate its use:
#!/usr/local/bin/perl -w
#
# test script for CGI module
#
use CGI::EZForm qw(form_start form_end draw);
# Create somewhere to put the form data
$form = new CGI::EZForm;
# Pre-set some form values
$form->{station} = 'JJJ';
# Get any form data provided from the browser
$form->receive;
# Start our web page to be returned to the browser ...
print "Content-type: text/html\r\n\r\n";
# probably good practice to add some HTML header etc. here
# Now let's print a form ...
print
$form->form_start(action => '/cgi-bin/test.pl'),
$form->draw(type => 'text', name => 'account',
label => 'Account number', size => 30),
$form->draw(type => 'radio', name => 'station',
values => ['JJJ', 'MMM'],
captions => ['Triple-J', 'Triple-M']),
$form->draw(type => 'select', name => 'choice', label => 'Choose',
selected => 'one',
options => ['First', 'Second', 'Third'],
values => ['one', 'two', 'three']),
$form->draw(type => 'submit', value => 'Send'),
$form->form_end;
exit;
=head1 METHODS
Available methods are:
=over
=item $form = CGI::EZForm->new;
Creates a new form:
In reality, this just creates a reference to a hash which will hold
the field values, so you can access particular form field values
directly, as in
$xyz = $form->{xyz};
providing you are not an OOP purist, I guess. (If you are, use the get
method.)
=item $form->set(PARAMS);
allows you to set value on one or more form fields. E.g.
$form->set(me => 'Tarzan', you => 'Jane');
Of course, you can just set individual fields using
$xyz = $form->{xyz};
which is probably faster.
=item $form->clear(KEYS);
clears form field values from the form. If called with no parameters,
clears all fields, otherwise clears only the named fields. E.g.
$form->clear; # clears all fields
$form->clear('name', 'addr'); # clears only the name and addr fields
=item $form->get(KEY);
returns the value of KEY. Included only for the OOP fanatic.
Utilitarians will use $form->{KEY} instead to retrieve values
directly.
=item $form->receive();
Probably the first call you'll want to make after new, receive will
check for incoming data by various methods, and fill your hash with
any values it finds.
=item form_start(PARAMS);
returns HTML for a form header:
$form->form_start( action => '/cgi/myscript.pl', method => 'POST',
enctype => $encoding, name => $name);
Everything can be defaulted except name. 'action' defaults to the
current script, which is common enough to be useful, so that you can
get away with just
$form->form_start();
This will produce the equivalent of this HTML:
<form action="$ENV{SCRIPT_NAME}" method="POST"
enctype="application/x-www-form-urlencoded">
=item $form->form_end();
returns the form end tag. If table formatting is on, then it also
returns html to close the table.
=item $form->draw(PARAMS);
returns a string of HTML to display a particular form "object"
( run in 2.379 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )