|
::Features
::Download
::Tutorial
::Examples
::Documentation ::Join the Mailing List ::List Archives ::Contribute |
|
NAMECGI::FormBuilder::Multi - Create multi-page FormBuilder forms
SYNOPSIS
use CGI::FormBuilder::Multi;
use CGI::Session; # or something similar
# Top-level "meta-form"
my $multi = CGI::FormBuilder::Multi->new(
# form 1 options
{ fields => [qw(name email daytime_phone evening_phone)],
title => 'Basic Info',
template => 'page1.tmpl',
validate => { name => 'NAME', email => 'EMAIL' },
required => [qw(name email daytime_phone)],
},
# form 2 options
{ fields => [qw(billing_name billing_card billing_exp
billing_address billing_city billing_state
billing_zip billing_phone)],
title => 'Billing',
template => 'page2.tmpl',
required => 'ALL',
},
# form 3 options
{ fields => [qw(same_as_billing shipping_address
shipping_city shipping_state shipping_zip)],
title => 'Shipping',
template => 'page3.tmpl',
required => 'ALL',
},
# a couple options specific to this module
navbar => 1,
# remaining options (not in hashrefs) apply to all forms
header => 1,
method => 'POST',
submit => 'Continue',
values => $dbi_hashref_query,
);
# Get current page's form
my $form = $multi->form;
if ($form->submitted && $form->validate) {
# Retrieve session id
my $sid = $form->sessionid;
# Initialize session
my $session = CGI::Session->new("driver:File", $sid, {Directory=>'/tmp'});
# Automatically store updated data in session
$session->save_param($form);
# last page?
if ($multi->page == $multi->pages) {
print $form->confirm;
exit;
}
# Still here, goto next page
$multi->page++;
# And re-get form (no "my" on $form!)
$form = $multi->form;
# Make sure it has the right sessionid
$form->sessionid($session->id);
# on page 3 we have special field handling
if ($multi->page == 3) {
$form->field(name => 'same_as_billing',
type => 'checkbox',
options => 'Yes',
jsclick => 'this.form.submit()');
}
}
# Fall through and print next page's form
print $form->render;
DESCRIPTIONThis module works with The multi-page ``meta-form'' is a composite of the individual forms you
specify, tied together via the special
my $multi = CGI::FormBuilder::Multi->new(...);
# current form
my $form = $multi->form;
$multi->page++; # page forward
$multi->page--; # and back
$multi->page = $multi->pages; # goto last page
# current form
$form = $multi->form;
To make things are fluid as possible, you should title each of your
forms, even if you're using a template. This will allow
METHODSThe following methods are provided:
new(\%form1, \%form2, opt => val)This creates a new In addition to a hashref, forms can be directly specified as a
When the first non-ref argument is seen, then all remaining args
are taken as common options that apply to all forms. In this way,
you can specify global settings for things like The SYNOPSIS above is very representative of typical usage.
|
| FormBuilder is © 2000-2006 Nate Wiger, with contributions from many people. |