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 7: Field Data Print

<< Multi-Select Lists | Field Attributes >>

As we mentioned, the standard way to get at field data is by using the field() option along with the name of the field you want, very similar to how's param() works:

$email = $form->field('email');    # get "email" field
In the case of multiple values (for example from a multiple select list), you can get all the values back simply by requesting an array:
@favorites = $form->field('favorite_colors');
In addition, there are a couple other things you can do. First, you can get a list of all field names by calling field() without any options in an array context:
@fields = $form->field;
for (@fields) {
    # debug field values, the join handles multi-valued fields
    warn "Value of field '$_' = " . join(',',  $form->field($_));
Second, and perhaps most useful, you can get all of the fields returned as a hashref if you call field() without any options in a scalar context:
$field = $form->field;           # hashref
warn "email = $field->{email}";
warn "mlist = $field->{mlist}";
The advantage to this last method is that you can use it directly in strings, and it's much quicker than a function call. The disadvantage is it will only return the first value of a field, so won't work for any fields that are multi-valued. (Note: If you don't know what a hashref is, don't worry, we'll discuss it in the Intermediate Tutorial.)

Important: In all cases, you will only be able to access those fields that you have explicitly defined via the fields option to new(). FormBuilder intentionally ignores any parameters not listed as valid fields for security reasons. To get to extra CGI parameters, you must use the cgi_param() function:

$company = $form->cgi_param('company');
This could be useful if you wanted to do rebranding of a website. For example, if a person went to, a different header may appear. However, you would not want this as a form field, since it would not be user-modifiable.

<< Multi-Select Lists | Field Attributes >>

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