Database Reference
In-Depth Information
labels
The labels to associate with each value. This argument is optional; if it's missing,
CGI.pm uses the values as the labels. Otherwise, the labels argument should be a
reference to a hash that associates each value with its corresponding label. For ex‐
ample, to produce a list element for cow colors, the values and labels are the same,
so no labels argument is necessary. However, to produce a state list, labels should
be a reference to a hash that maps each state abbreviation to its full name.
default
The initially selected item in the element. This argument is optional. For a radio
button set, CGI.pm automatically selects the first button by default if this argument
is missing. To defeat that behavior, provide a default value not present in the val
ues list. (This value cannot be undef or the empty string.)
Some of the functions take additional arguments. For radio_group() , you can supply
a linebreak argument to specify that the buttons should be displayed vertically rather
than horizontally. scrolling_list() takes a size argument indicating how many items
should be visible at a time. (The CGI.pm documentation describes additional arguments
that are not used here at all. For example, there are arguments for laying out radio
buttons in tabular form. We won't be that fancy.)
To construct a form element using the colors in the cow_color table, begin by retrieving
them as an array:
my $color_ref = $dbh -> selectcol_arrayref ( qq{
SELECT color FROM cow_color ORDER BY color
} );
selectcol_arrayref() returns a reference to the array, exactly the kind of value needed
for the values argument of the CGI.pm functions that create list elements. To create a
group of radio buttons, a pop-up menu, or a single-pick scrolling list, invoke the func‐
tions as follows:
print radio_group ( - name => "color" ,
- values => $color_ref ,
- linebreak => 1 ); # display buttons vertically
print popup_menu ( - name => "color" ,
- values => $color_ref );
print scrolling_list ( - name => "color" ,
- values => $color_ref ,
- size => 3 ); # display 3 items at a time
The values and the labels for the color list are the same, so no labels argument need
be given; CGI.pm uses the values as labels by default. Note that we haven't HTML-
encoded the colors here, even though some of them contain an & character. CGI.pm
Search WWH ::




Custom Search