Gossamer Forum
Home : Products : DBMan : Customization :

Build Select Option Field From Other DB

Quote Reply
Build Select Option Field From Other DB
Hi,
I know how to build a select option field when you give the options in the config file, but it there away to move the values out of the config file, and into a separate file?
Thanks in advance
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
I've got some code that extracts from a simple text file to build a list. Is that similar to what you want?

Quote Reply
Re: Build Select Option Field From Other DB In reply to
Yeah this would be smashing, thanks, if you could post either here, or to ben@hot-key.com I'd be very greatful!
Thanks
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
Try this:-
1. remove any values in %db_select_fields in your cfg file.
2. in sub html_record_form in yout html.pl on the field that you want to build a list for e.g. :-

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>List Category:</FONT></TD>

<TD VALIGN="TOP">|;
open(SELECT,"/full/path/to/textfilelocation/catlist.txt") || die "Can't open file";
@category_list = (<SELECT> );
close (SELECT);
print qq|<select name="Category Title">|;

foreach (@category_list) {
chomp $_;
print "<option";
print " SELECTED" if ($rec{'field_name_to_store_value'} eq "$_");
print ">$_\n";
}
print qq|</select>
</TD></TR>

Obviously change the field names to suit your needs and use the correct full path to the location of the textfile. The text file detailed in the textfilelocation/catlist.txt needs your values on each line with a <CR>. Upload and set as 644.

See how that goes,
Rob


Quote Reply
Re: Build Select Option Field From Other DB In reply to
Great thanks I'll give it a try!

Quote Reply
Re: Build Select Option Field From Other DB In reply to
This worked great thanks. Just 1 thing, in the cfg file, I had the value so that 1 thing was shown in the select field, but another was inserted in the database i.e.

%db_select_option_fields = (
RTY => 'Twin|A2T,Junior|ATS,Suite|AS1,Double|B1K,Single|B1T,'
);
This way if you select 'Twin' from the select field, 'A2T' is entered into the database! Is there away to do this from another file? Currently the select field just displays 'TWIN|A2T'
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
Not sure I follow sorry Frown.

You don't need the select values in the cfg is your pulling from another file or am I missing the point?

Quote Reply
Re: Build Select Option Field From Other DB In reply to
what i want is to pull values for a select field from another file, but then have different values entered into that database. So say you have a select field, that gets its options from another file, with, 'Option1, Option2, Option3', if you select option 1, the code "op1" gets entered in the database, not option1. I need to be able to have codes for my different options entered into the database. Users don't know what the codes are, they just select the options, and the code is entered. Thats how I had the cfg file set up. Have I explained ok? I know its confusing!
Thanks for your help so far.
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
Hi Ben, looks like someone else is doing something similar in this thread
http://gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=DBCust&Number=116305&page=0&view=collapsed&sb=5

Subject Expanding Abbreviations ... in this forum.

Perhaps that solution would work for this instance.

Quote Reply
Re: Build Select Option Field From Other DB In reply to
I had a look at the above string, but I think it only replaces a single code! Is that right? Not sure, I have close to 50 codes! Can it be converted to replace that many?
Anyway I'm still struggling on, I have put a quick fix in at the moment, with separate copies of DBMan in different directores, for each user, this way I can store the values for each user in the config file. However I'd still like to have just 1 copy of DBMan in the end, for all users.
Thanks for the help so far
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
Do you think there would be away to modify the following code so that you can: -
1. Have options shown in the select menu, but different values entered in the database (i.e. Option1 = Op1)
2. Have different Options depending on which user logs in!

code for html.pl
----------------------
open(SELECT,"/var/lib/apache/cgi-bin/user.db") || die "Can't open file";
@category_list = (<SELECT> );
close (SELECT);
print qq|<select name="TEST">|;
foreach (@category_list) {
chomp $_;
print "<option";
print " SELECTED" if ($rec{'TEST'} eq "$_");
print ">$_\n";
}
print qq|</select><td>
----------------------
The external file would be formated like this

userid~option1|code1,option2|code2,option3|code3

An example of what i need would be like this

user001~Single|Sgl,Double|Dbl,Twin|Twn
user002~Single|Sgl,Twin|Twn,Tripple|Tpl

The 1st coloum will always be userid, every coloum after is an option, and its code, split with a | (pipe)!

Is there anyway at all to do this?

Many Regards
Ben

Quote Reply
Re: Build Select Option Field From Other DB In reply to
i did this with thE "COUNTRY CHOOSE" JAVASCRIPT...AND MAKE REFERENCE TO IT LIKEsub html_add_form {
# --------------------------------------------------------
# The add form page where the user fills out all the details
# on the new record he would like to add. You should use
# &html_record_form to print out the form as it makes
# updating much easier. Feel free to edit &get_defaults
# to change the default values.

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Add a New Record.</title>
<SCRIPT LANGUAGE="Javascript" SRC="/docs/javascripts/clothes_item.js">
</SCRIPT>
</head>

THIS WOULD HAVE TO BE PUT IN (8) SUB HTML RECORDS