|
::Features
::Download
::Tutorial
::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute |
|
Basic Tutorial - Step 10: Custom Headers
If you've been paying attention, you've noticed that all of our
if ($form->submitted) {
print $form->confirm(header => 1);
} else {
print $form->render(header => 1);
}
This automatically generates a CGI header for you, along with some leading
HTML like a title, body tag, and so forth.
But often, you'll want to include your form as part of a bigger page, possibly with its own navbar, images, stylesheets, and so on.
In this case, you should turn off the
#!/usr/bin/perl
use CGI;
use CGI::FormBuilder;
@fields = qw(username password confirm_password);
$query = CGI->new; # must use OO version
$form = CGI::FormBuilder->new(
fields => \@fields,
params => $query, # get CGI params from CGI.pm
font => 'verdana'
);
print $query->header; # use CGI.pm header
# open and print your custom HTML
open H, "<header.html";
print while <H>;
close H;
if ($form->submitted) {
print $form->confirm; # no header option
} else {
print $form->render; # no header option
}
You have to use the Object-Oriented calling style of CGI.pm,
so that FormBuilder can still get to the CGI parameters even after CGI.pm
has already processed them. Don't worry, CGI.pm is still easy to use.
Just prefix your normal calls to CGI functions with the string $query->.
For example:
use CGI qw/:standard/; # standard
use CGI; # 00 form
$query = CGI->new; # 00 form
$name = param('name'); # standard
$name = $query->param('name'); # 00 form
print header(); # standard
print $query->header; # 00 form
Remember, you only have to do this if you're generating your own
custom headers. In fact, there are even better ways to get the proper
HTML layout using Templates, as we will see in the "Advanced" section.
The above method is easy to use if you're looking for something simple.
|
| FormBuilder is © Nate Wiger, with contributions from many people. |