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

Basic

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

Intermediate

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

Advanced

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 5: Field Options Print

<< Input Validation | Multi-Select Lists >>

By default, all fields are of type text, again, just like the HTML spec says. This has worked so far, but often you'll want a select list, set of checkboxes, etc.

This is one area where FormBuilder really shines: input field abstraction. Make sure you understand this next part.

FormBuilder maintains all form fields as data entities. Not "checkboxes", but fields. FormBuilder will actually decide for you what the best HTML representation is based on the number of options a field has. When a field has no options (the default case), then the field is a simple text input. The more options you specify, the more extensive the representation to the user.

To change the number of options, you use the field() method. Remember earlier when we mentioned it had a number of uses? Any time you want to change an individual field's properties, you use field(). For example:

@options = qw(Subscribe Unsubscribe);
$form->field(name => 'mailing_list',
             options => \@options);      # add options
Here, we've given the mailing_list field two options: "Subscribe" or "Unsubscribe". Since there are only two options, they will be presented in a radio group, like so:
<input name="mailing_list" type="radio" value="Subscribe"> Subscribe 
<input name="mailing_list" type="radio" value="Unsubscribe"> Unsubscribe
FormBuilder is smart enough to automatically change the HTML representation from text to radio, just because it sees options for the field! And if you were to specify several more options, it would automatically change the field to a select list. Finally, a single-option list will become a checkbox, since this allows the user to deselect it.

While FormBuilder does all this for you, if you want to force something to be a specific HTML input type, you can do so very easily. Simply specify the type argument to field():

$form->field(name => 'mailing_list',
             type => 'select',
             options => \@options);
This would force mailing_list to be represented as a select list. Before you do this, though, I encourage you to play around with FormBuilder's "smartness" a little, you just may like it. :-)

Regardless, in all cases you get to the data the exact same way:

$mlist = $form->field('mailing_list');
FormBuilder addresses all data as fields - it doesn't care if something's a select list, textarea, or file upload. Getting to the data is always done the same way.

<< Input Validation | Multi-Select Lists >>

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