Gossamer Forum
Home : Products : DBMan : Customization :

Multiple select field, Dropdown not opening

Quote Reply
Multiple select field, Dropdown not opening
Hi again,

This time I am having trouble with a multiple select field. It changes the keywords in the category when I click up or down, but I only see one keyword at the time. Also - when I opens a record with two keywords in the same field for modification this field is blank.

You'll find my dbman at www.nicklisten.no/cgi-bin/dbman/db.cgi The field in question is "Land".

Any thoughts?

My files can be found at:
www.nicklisten.no/files/db_pl.txt
www.nicklisten.no/files/default_cfg.txt
www.nicklisten.no/files/html_pl.txt

Jan Peter
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
Try using this version of the sub for multiple select:

sub build_multiple_select_field { ### this one works with spaces in select lists ##
# --------------------------------------------------------
# Builds a SELECT field based on information found in the database definition. Parameters are the column to build, a default value, a default name, and the size of the box.

my ($column, $value, $size) = @_;
my (@fields, $field, @selectfields, @lines, $line, $output);

$size || ($size=3);

@values = split (/\Q$db_delim\E/,$value);
@fields = split (/\,/, $db_select_fields{$column});

if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}

else {
$output = qq|<SELECT NAME="$column" MULTIPLE SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$selected = 0;
foreach $value (@values) {
if ($value eq $field) {
$output .= "<OPTION SELECTED>$field\n";
$selected = 1;
}
}
unless ($selected) {
$output .= "<OPTION>$field\n";
}
}
$output .= "</SELECT>";
}
return $output;
}


You can also change the field so it will display 3 choices visible in the select list by using:

print &build_multiple_select_field("Land","$rec{'Land'}",3); print qq|

in your sub html_record_form

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
Thank you again LoisC! This worked.
But, the category count on the homepage doesn't count correctly when I use the Multiple select field. Do you know anything about this?

Edit:
It counts multiple select fields with one keyword correct. It also searches correct and finds the records with muliple select field with more than two keywords. So the problem is only the counting of fields with more than one keyword.

Jan Peter

Last edited by:

JPWiese: Jun 1, 2004, 11:29 PM
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
There are different variations of the category list. You may not be using the one specific for multiple select lists.

Try this one:

=SINGLE COLUMN - MULTIPLE SELECT ==============

for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if ($found) {
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);
## ------- changed for use with multiple select categories -----
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}
## -------------
}
close DB;

@options = split (/\,/, $db_select_fields{'Category'});

foreach $option (sort @options) {
unless ($count{$option}) {
$count{$option} = '0';
}
$encoded = &urlencode($option);

print qq|<A HREF="$db_script_link_url&sb=$sort_field&so=$sortorder&Validated=Yes&Category=$encoded&view_records=1">$option</A> ($count{$option})<BR>|;
}
}

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
The one I used was this:

Code:
sub build_multiple_select_field { ### this one works with spaces in select lists ##
# --------------------------------------------------------
# Builds a SELECT field based on information found in the database definition. Parameters are the column to build, a default value, a default name, and the size of the box. my ($column, $value, $size) = @_;
my (@fields, $field, @selectfields, @lines, $line, $output); $size || ($size=3); @values = split (/\Q$db_delim\E/,$value);
@fields = split (/\,/, $db_select_fields{$column}); if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
} else {
$output = qq|<SELECT NAME="$column" MULTIPLE SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$selected = 0;
foreach $value (@values) {
if ($value eq $field) {
$output .= "<OPTION SELECTED>$field\n";
$selected = 1;
}
}
unless ($selected) {
$output .= "<OPTION>$field\n";
}
}
$output .= "</SELECT>";
}
return $output;
}


I took this ot and pasted in the one you suggested. Instead of "Category" I used "Land". Then I got a 500 internal server error.

Jan Peter
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
Can you make a new copy of your .txt files on the server. If so, I'll download them to my computer and test it locally on my server.

It would also help to have a copy of your db file so I have something to test with.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
Of course I will update the files.

My files can be found at:
www.nicklisten.no/files/db_pl.txt
www.nicklisten.no/files/default_cfg.txt
www.nicklisten.no/files/html_pl.txt
www.nicklisten.no/files/default_db.txt

Jan Peter
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
I already made a copy of your old files and made the changes I gave you :) Hopefully i had the latest changes, but the script is running on my local server with no errors after making a few changes:

I forgot that with that version of the list categories mod you also need to add the the following sub within your db.cgi file:

sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;
}

If you want to have the select field displayed in 2 columns use this version:

|;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Land" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if ($found) {
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 ($fields[2] eq "Yes") { ### validation field
## ------- changed for use with multiple select categories -----
@values = split (/\Q$db_delim\E/o, $fields[$fieldnum]);
foreach $value (@values) {
if (!(grep $_ eq $value, @selectfields)) {
push (@selectfields, $value);
}
++$count{$value};
}
## -------------
}
# } # end validation check
close DB;
@options = split (/\,/, $db_select_fields{'Land'});
my $half = int (($#options+2) / 2);
my $i = 0;
print qq|<CENTER><TABLE width="460" border=0 cellspacing="0" cellpadding="10"><TR><TD valign="top" width="225"><$font> |;

foreach $option (sort @options) {
unless ($count{$option}) {
$count{$option} = '0';
}
$encoded = &urlencode($option);

if ($i == $half) {
print qq|</font></TD><TD valign="top" width="225"><$font>|;
}
$i++;

print qq|<A HREF="$db_script_link_url&sb=$sort_field&so=$sortorder&Validated=Yes&Land=$encoded&view_records=1">$option</A> ($count{$option})<BR>|;
}
}
print qq| </font></TD></TR></TABLE></CENTER>|;

==========

In sub html_record and html_record_long, just after

my (%rec) = @_;

add this line:

$rec{'Land'} =~ s/\|/, /g; ## display multiple selects with space and comma

This will cause all of the | characters to be replaced by a "comma-space" before they are printed out.

=============

In your short display why not use:

print qq|
<A HREF="$long_url">$rec{'Nick'}</A></TD><TD>$rec{'Fylke'}</TD><TD>$rec{'Land'}</TD><TD>$rec{'EndretDato'}
|;

In html_view_success you can state the table width to have it space the columns nicely.

print "<table width=450>";

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/

Last edited by:

LoisC: Jun 2, 2004, 12:19 PM
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
I still get the 500 error. My error.txt (www.nicklisten.no/error.txt) says:

Quote:

syntax error at db.cgi line 1340, near "|"
Execution of db.cgi aborted due to compilation errors.


Line 1340 starts with the code you just posted

Code:

|;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Land" ) {
$fieldnum = $i; $found = 1;
last;
...

Jan Peter
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
I don't know why you are getting that error? I don't get any when running it from my server.

I do notice that for some reason it is adding a # 1 in the Epost field when trying to add a record.

I'll attach a copy of the html.pl and db.cgi file I was testing with the latest changes.

I pulled a muscle in my back the other day and can only stay at my computer for awhile before I have to go lay down. I'm going to take a nap and will come back in a few hours to see if you got it to work.

I'll also see why it's not pulling in the email ... I'm thinking you are trying to pull this from the password file?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
I used the db.cgi and html.pl you attached and everything worked fine. Did you change a lot in there?
I don't see any #1 in the email field. I have two email fields. One that is used for signup and receiving new passwords - viewable only for the admin and one people can fill in if they want visitors to see their emailaddy. It can be another email than the one they used for signup.

Is it possible to hide keywordcounts with zero records?

Thank you so much for your help and I hope Your back gets better. I know how bad that can be.

Jan Peter
Quote Reply
Re: [JPWiese] Multiple select field, Dropdown not opening In reply to
I didnt' add anything that wasn't stated in one of the above posts.

Sorry, the 1 showing up in the email field was due to me not having the password file to include the email addy :)

I think there is a version which will hide records with zero counts, I'll check the FAQ and see if I have a copy of that version.

Your welcome I'm glad I could help, and happy you have it up and running.

------------

JPDeni's category list #3 is for only displaying record with counts.

I think the only change you would need to make is to replace these commented out lines:

# foreach $option (sort @options) {
# unless ($count{$option}) {
# $count{$option} = '0';
# }
# $encoded = &urlencode($option);

with:

foreach $option (sort @options) {
if ($count{$option}) {
$encoded = &urlencode($option);

then add another closing } before:

print qq| </font></TD></TR></TABLE></CENTER>|;

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/

Last edited by:

LoisC: Jun 2, 2004, 9:55 PM
Quote Reply
Re: [LoisC] Multiple select field, Dropdown not opening In reply to
That worked fine - Thank you again.

I am off to start my next project - Relational database

Bye for now

Jan Peter