The following is from the Links script:
Code:
sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition. Parameters are the column to build,
# a default value, a default name, whether to allow multiple selections,
# and the size of the box.
my ($column, $value, $name, $mult, $size) = @_;
my (@fields, @values, $ouptut);
$name | | ($name = $column);
$size | | ($size = 1);
if ($mult) { @values = split (/\Q$db_delim\E/,$value); }
else { @values = ($value); }
@fields = split (/\,/, $db_select_fields{$column});
if (! exists ($db_select_fields{$column})) {
$output = "error building select field: no fields specified/unkown field ($column)!";
}
else {
$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (sort @fields) {
if (grep $_ eq $field, @values) {
$output .= "<OPTION SELECTED>$field\n";
}
else {
$output .= "<OPTION>$field";
}
}
$output .= "</SELECT>";
}
return $output;
}
If you replace this with the build_select_field subroutine in db.cgi, you can build your regular select fields the same way as you always have --
&build_select_field("fieldname","$rec{'fieldname'})
But if you want one to be a multiple select field, call it by using
&build_select_field("fieldname","$rec{'fieldname'},"fieldname","MULTIPLE",
3)
You can change the
3 above to whatever size you want for the select field.
I've used this and it works great for me.
------------------
JPD