Perl Form Builder ::Features ::Download ::Tutorial ::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute
Note: The mailing list is has been replaced by the Google FormBuilder Group


1. Intro to FormBuilder
2. A Simple Form
3. Form Method
4. Input Validation
5. Field Options
6. Multi-Select Lists
7. Field Data
8. Field Attributes
9. HTML Formatting
10. Custom Headers
S. Summary


1. Trickier Forms
2. Perl References
3. Default Values
4. CGI Stickiness
5. JavaScript Actions
6. Input Validation 2
7. Multiple Submits
8. JavaScript Actions 2
9. Modules & mod_perl
10. Smartness
S. Summary


1. Remaining Features
2. Intro to Templates
3. HTML::Template
4. HTML::Template 2
5. Template Toolkit
6. Exploiting render()
7. Multi-Screen Apps
8. Multi-Screen Apps 2
9. Multi-Screen Apps 3
10. Custom Messages
S. Summary

Basic Tutorial - Step 10: Custom Headers Print

<< HTML Formatting | Summary >>

If you've been paying attention, you've noticed that all of our print statements have specified the header option:

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 header option by simply omitting it. Then, use some other module to generate your header and leading HTML. The only trick you have to remember is that when you use FormBuilder with other CGI modules, you have to tell it explicitly where to get the CGI request parameters from by using the params option:


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
              font   => 'verdana'

print $query->header;              # use 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, so that FormBuilder can still get to the CGI parameters even after has already processed them. Don't worry, 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.

<< HTML Formatting | Summary >>

FormBuilder is © Nate Wiger, with contributions from many people.