Gossamer Forum
Home : Products : DBMan : Customization :

Combing functionality of two mods

Quote Reply
Combing functionality of two mods
Another question for the masses :)

I am using the sub build_select_field_from_db mod and it works great. (see below) However I want the user to be able to select multiple items from this dropdown menu. Ultimately it would take altering the sub build_select_field_from_db mod (also below) to incorporate functionality from the sub build_multiple_select_field but I am not sure how to do this without messing up what I have already working. Does anyone have any ideas?

sub build_select_field_from_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;

$name || ($name = $column);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
if (!$found) {
return "error building select field: no fields specified!";
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
close DB;

$output = qq|<SELECT NAME="$name"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
$output .= "</SELECT>";
return $output;

sub build_multiple_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found in the database definition.
my ($column, $value, $size) = @_;
my ($size, %values);

$name || ($name = $column);
$size || ($size = 1);

@fields = split (/\,/, $db_select_fields{"$column"});
%values = split (/\Q$db_delim\E/, $value);
($#fields >= 0) or return "error building select field: no select fields specified in config for field '$column'!";
$output = qq|<SELECT NAME="$name" MULTIPLE SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
$output .= "</SELECT>";
return $output;
##### end build_mulitiple_select ########

As for where to put the print &build_multiple_select_field line,
it goes in html_record_form, where you would put a

print &build_select_field

This won't work with autogenerate.

You'll need to have a select field defined in your .cfg file with all the states in it.

Also, it would be a very good idea to have separate input and search forms.

Use the multiple select field for the input, but a "single" select field for the search.

To print out the multiple select field, use

print &build_multiple_select_field("Category","$rec{'Category'}",3);

The 3 above is the size of your select field.
I haven't used this directly, but I've used something similar that worked very well.
Subject Author Views Date
Thread Combing functionality of two mods chronisca 2196 Jun 7, 2004, 1:32 PM
Post Re: [chronisca] Combing functionality of two mods
LoisC 2113 Jun 7, 2004, 6:59 PM