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

Advanced Tutorial - Step 10: Custom Messages Print

<< Multi-Screen Apps 3 | Summary >>

The last topic we'll cover is custom messaging. Most of the time, the built-in FormBuilder messages are sufficient. However, you may be writing a multi-lingual application, or something else that requires precise control over messages.

FormBuilder's messaging system is very easy to understand. Each message is given a unique tag by FormBuilder. For example, the message that is used in a JavaScript alert about an invalid select list is called js_invalid_select.

Each message you want to customize is specified to the messages parameter to new(), along with what you want the message to say:


use CGI::FormBuilder;

$form = CGI::FormBuilder->new(
             fields => [qw/name email phone/],
             messages => {
                js_invalid_start  => 'There were %s errors found:',
                js_invalid_text   => '- The "%s" field was invalid',
                js_invalid_end    => 'For more help, click the "Help" button',
                form_invalid_text => 'This field is missing or invalid',

print $form->render(header => 1);
Alternatively, you can put these specifications in a separate file, one per line, separated by a space between them:
# messages.en - messages for English
js_invalid_start    There were %s errors found:
js_invalid_text     - The "%s" field was invalid
js_invalid_end      For more help, click the "Help" button
form_invalid_text   This field is missing or invalid
(Note: You do not use quotes or commas in this file.) Then, you simply specify the filename to your form:

use CGI::FormBuilder;

$lang = $ENV{HTTP_ACCEPT_LANGUAGE} || 'en';      # language

$form = CGI::FormBuilder->new(
             fields => [qw/name email phone/],
             messages => "messages.$lang",       # messages file  

print $form->render(header => 1);
FormBuilder will issue a warning if it can't open the specified filename, and then will continue using the default messages. Any messages not explicitly specified will remain the same as the defaults.

If you're interested in custom messages, please view the complete list of custom message tags.

<< Multi-Screen Apps 3 | Summary >>

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