Gossamer Forum
Home : Products : DBMan : Customization :

Multiple Select?

(Page 1 of 2)
> >
Quote Reply
Multiple Select?
Hi, I am a Database, DBman and Perl newbie from Norway. I run a website where members of a discussionboard can post a presentation of themselves and family. It is a forum for families with adopted children. I receive their presentation via email every time someone becommes a member or the members updates their presentation. Then I manually update the website.

All the members (250 - 300) resides in a main list, a list for where they live (county), a list for where their children are from (country) and a list for those with an emailadress or a website (links). Some members will be in more "country" list because they have adopted children from more than one country.

I would like to use DBman for this. I have it up and running, but can't get JPDeni's Multiple select MOD to work at all (more than one country for some families) How do I do this? Is there a better (easyer) way to get the same result?

Is there anyone who knows what I should/could do?

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
This is the version I have the most success with:

sub build_multiple_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, $size) = @_;
my (@fields, @values, $output);

$size or ($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="$column" MULTIPLE 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;
}

Then in your html.pl file within sub html_record_form when you define your multiple select field use:

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


In your .cfg file be sure you have the select field defined as a select

'Country' => [ 5,'alpha',0,50,1,'',''], # multiple select


%db_select_fields = (
'Country' => 'Afghanistan,Albania,Algeria,American Samoa,Andorra,Angola,Anguilla,Antarctica'
);

Adding all your country selections above. Be sure you don't have any spaces between the country names.

Hope this helps, if not, perhaps if you make a .txt copy of your files and post the url to where they can be viewed we can help you get this working.

Please state exactly what is not working.

P.S. It might help to include a note to your users to hold down the CTRL key while making multiple selections.

Unoffical DBMan FAQ

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

Last edited by:

LoisC: Apr 28, 2002, 11:14 AM
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Hi LoisC, Thank you for the help.

I must be doeing something wrong somewhere Frown I can't get it to work.

I copied the files to txt files as you said. You find them in:

http://www.nicklisten.com/dbman/db_cgi.txt
http://www.nicklisten.com/dbman/default_cfg.txt
http://www.nicklisten.com/dbman/html_pl.txt

(I think I should go out and buy me a book on perl :-)

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
I checked over your files and didn't find anything that would cause problems with the muliple select mod.

Then I tried to access your database to see if I could view your current records and received an error.

Since you don't have debugging turned on, I could not see any error messages. Please try moving the line:

$db_debug = 0;

within your .cfg file to the top of the file above the section:

# File and URL's

and turn debugging on so we can try and find the error.

Or you can add the snippet of code to get useful error messages to all your files.

In your .cgi file add after #!/usr/bin/perl

BEGIN {
open (STDERR, ">/data1/hypermart.net/webmagic/error.txt");
}

changing the above to be the full PATH to your error.txt file. And in your .cfg and html.pl file just add to the very top. Then create and upload your error.txt and modified files.

You might also want to modify the lines in your html_record_form to read as follows:

print qq| <TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC"> |;
if ($per_admin) { print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>ID:</FONT></TD> <TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="ID" SIZE="20" VALUE="$rec{'ID'}" MAXLENGTH="255"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>UserID:</FONT></TD><TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="UserID" SIZE="20" VALUE="$rec{'UserID'}" MAXLENGTH="255"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Dato:</FONT></TD><TD VALIGN="TOP" WIDTH="475">&nbsp;<INPUT TYPE="TEXT" NAME="Dato" SIZE="20" VALUE="$rec{'Dato'}" MAXLENGTH="255"></TD></TR> |;
}
else {
print qq|<TR><TD colspan=2> <input type="hidden" NAME="ID" VALUE="$rec{'ID'}">
<input type="hidden" NAME="UserID" VALUE="$rec{'UserID'}">
<input type="hidden" NAME="Dato" VALUE="$rec{'Dato'}"> </TD></TR> |;
}

This way when the hidden fields are included they are also within table tags, as they within the table.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Hi again,

I have moved $db_debug = 0; and turned it on. I see that I also (not or) have copied:

In your .cgi file add after #!/usr/bin/perl

BEGIN {
open (STDERR, ">/data1/hypermart.net/webmagic/error.txt");
}

...and made an error.txt file. I chmod it to 666.

Will there be a problem when I did both?

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
No there won't be a problem using both, but you need to change this PATH to match that needed for your server and actual path.

open (STDERR, ">/data1/hypermart.net/webmagic/error.txt");

Was just an example of the path used for one of my sites.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I did so in db.cgi, default.cfg and html.pl

Should I put it any other places?

Jan Peter
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I did notice in your html.pl file in sub html_record_form you have two closing table tags. You only started one table so you should remove the 2nd. The debug is not showing us any useful information.

Please fix the path mentioned above for the error.txt and let's see if it will provide any help. It's probably best to put the error.txt file in your root directory.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
That should work fine putting them in just those files.

I spoke to soon and when viewing the source it did display the error:

fatal error: Undefined subroutine &main::build_select_field called at /home/nicklist/www/cgi-bin/dbman/db.cgi line 1027.

Did you by any chance remove this sub from your db.cgi file?

Let me go back and look at your db.cgi file again.

yes, that sub is now missing. you need to add it back to your db.cgi file, hopefully you have a backup file you saved before making changes if not here is a copy of that sub:

sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found in the database definition. Parameters are the column to build and a default value (optional).

my ($column, $value) = @_;
my (@fields, $ouptut);

@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"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
}
return $output;
}

Unoffical DBMan FAQ

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

Last edited by:

LoisC: Apr 28, 2002, 1:55 PM
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I used JP Deni's homepage when I set it up. I got it to work before I entered the Multiple select changes

Jan Peter
Quote Reply
Re: [LoisC] Multiple Select? In reply to
OK I copied your code ...multiple... over this code. I thought it should be used instead. Now I have copied the missing code just before ...multiple... and the database is back up. Now - how can I add a record with more than two countries or Land as I call it in Norwegian?

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
But somehow that sub got deleted or perhaps you replaced it with a modified version for the multiple select first.

I realize that you used the configurator, but it does add a lot of extra coding with the forms. It's best to use it as a guide and then condense it :)

By the way the path to your error.txt could be:

open (STDERR, ">/home/nicklist/www/error.txt");

according to the debugging script.

Unless you add that missing sub it will not display when clicking on List All. Do you currently have record in your database?

You need that sub for this field:

|; print &build_select_field("Fylke",$rec{'Fylke'}); print qq|

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I have to look at that in the morning. It is 11:30 pm and I am off for work in 6 hours. Thank you so far. I realy appreceate (I never learn how to spell this) your effort.

Jan Peter
Quote Reply
Re: [LoisC] Multiple Select? In reply to
You said that the path to my error script could be
open (STDERR, ">/home/nicklist/www/error.txt");
Should I move the errorscript there?

Yes I used a configurator. I thought I should get a working database before I tried condensing it (I guess that means cleaning)Smile

I haven't started adding records yet. Should I add some testrecords before I go on?

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
Now I can create accounts, add, modefy and or delete records, but the multiple select still doesn't work. Should I make new copies of db.cgi, default.cfg and html.pl (--> .txt) or do you see my files as they are?

Jan Peter

Last edited by:

JPWiese: Apr 28, 2002, 10:43 PM
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
I'm glad you got it up and running :)

Yes, you would need to make new copies of your files to show the changes you made. It does help to place some test records to be sure everything is working.

I'll try and access it and see if I can help you figure out why the multiple select isn't working. You are using the CTRL key while making your selections right?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Yes I (try to) use the ctrl key when I add records. The new copies of db.cgi, default.cfg and html.pl are now in

www.nicklisten.com/dbman/db_cgi.txt
www.nicklisten.com/dbman/default_cfg.txt
www.nicklisten.com/dbman/html_pl.txt

Jan Peter
Quote Reply
Re: [LoisC] Multiple Select? In reply to
That is very strange that it is not recognizing the field as a multiple select or displaying the options as 5 down as you have it defined.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I just noticed you have:

$db_auto_generate = 1;

in your .cfg file. You will want to turn that off as you have defined your forms. Let's see if that makes a difference.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
I changed it to $db_auto_generate = 0; And it worked, But (there's allways a but) There is still something wrong:

ERROR: Unable to Modefy Record

There were problems modifying the record:
  • Land (Too long. Max length: 11)



Please fix any errors and submit the record again.

Jan Peter
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
Yeah!! You got it working. Now that you are hiding the userid field to all but admin you may want to make the following changes in your db.cgi file so that it will automatically add the username in your add form:

In sub get_defaults replace:

foreach $field (keys %db_defaults) {
$default{$field} = $db_defaults{$field};
}

with:

foreach $field (keys %db_defaults) {
$default{$field} = $db_defaults{$field};
####### add userid in add form ###########
unless ($per_admin) { ($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid); }
}

In sub add_record instead of:

# Set the userid to the logged in user.
##### ($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

use:

# Set the userid to the logged in user (except if admin).
unless ($per_admin) { ($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid); }


Okay, with your current error, just change the length of your field to a very high number such as '255' this will allow the use of many country selections.

You might also want to add this line at the top of your html_record:

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

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Do I add this at the very top in sub html_record - like this?

sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

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

my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

Jan Peter
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Is it possible to automaticly add the date a new record is created and another date when the record is modefied? So I can have a page that shows last 5 added (new) records and a page that shows the last 5 modefied records?

Maybe the dates should be visible? How do I do that?

How can I have the total number of records on a certain page?

This was a lot of questions - Please let me know if it is to mutch

Jan Peter

Last edited by:

JPWiese: Apr 29, 2002, 8:22 AM
Quote Reply
Re: [JPWiese] Multiple Select? In reply to
You would put

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

after:
my (%rec) = @_; # Load any defaults to put in the VALUE field.

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

Is it possible to automaticly add the date a new record is created and another date when the record is modefied? So I
can have a page that shows last 5 added (new) records and a page that shows the last 5 modefied records?

You can setup a field for when the record is modified or you can have the date changed when a record is modified.

Maybe the dates should be visible? How do I do that?

Just change it to not being a hidden field in your display

How can I have the total number of records on a certain page?

This would be set in your .cfg file using the setting: $db_max_hits = 20;

This was a lot of questions - Please let me know if it is to mutch

I think you will find all your answers and many more tips and tricks by visiting the FAQ noted below. Your answers to the date questions can be found under the section "Dates".

Checking the FAQ you will see various options and can then decide what will work best for your project.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple Select? In reply to
Thank you for all your help. The database is up and running with multiple select. I se that I have a lot to learn. I better take a trip to my bookshop and see what they have on perl...

Jan Peter
> >