Gossamer Forum
Home : Products : DBMan : Customization :

adding to select list

Quote Reply
adding to select list
i want to have a select field from db that can be added to "on the fly" -- that is, when adding a new record (or modifying a record), the form would pull the values for Category that are already in the db. if the category i want has not yet been entered, i want to be able to type the new category in a text box and have it update the Category field (not a new field). then if i add another new record, that category will appear in the select list.

i found one old record that sounds like what i want but it is very old and i don't think it works with latest version of dbman (not sql):

see http://www.gossamer-threads.com/..._select_from_db;#404
Quote Reply
Re: [delicia] adding to select list In reply to
There are a few other threads which address this topic. Taken from the FAQ (under fields) check out these threads. The FAQ title is what you can searchon within the FAQ the Topic and date is what you can search on within the GT fourm.:


FAQ title: Select and Text name for same field?
Topic: Can you have a Select & Text name for same field?
TheFew 05-May-2000


FAQ Title: Self maintaining drop down select field
Topic: Self maintaining drop down...
Chris071371 23-Aug-1999

Hope this helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] adding to select list In reply to
yes, i had already seen those and the second one looked like what i wanted. but i cannot make it work. it looks like the guy posted his fix as displaying an entirely different field instead of adding the new item to lookup list.

the first thread seems to store new value in a separate file. but i'll study it a little more! thanks for the direction.

Last edited by:

delicia: May 15, 2004, 9:57 AM
Quote Reply
Re: [delicia] adding to select list In reply to
from one of the threads:

There are two ways around this, but I'm not sure if you'll want to do either one. One is to use the "build_select_field_from_database" option, which will list every option that has been entered in that field. If there is a new one, the user can enter it into the text field and, when he modifies his record, the rank will be selected in the select field. If you wanted to do that, you would delete the VALUE="$rec{'Rank'}" part of the text field.

this is what i want. i don't have many records and want to use the buildfromdb option. i put the text input field in the same td tag under the select field (&build_select...). when i don't select anything from the select box and type text in the text box, the text i type is not being saved. i can't figure out why???

from db.cgi:

sub build_select_field_from_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my ($name, @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;
last;
}
}
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;
}

########

then later:

elsif ($db_select_fields_from_db =~ $field) {
$output .= "<TR><TD align=right valign=top width=20%>$field:</TD><TD width=80%>" . &build_select_field_from_db($field, $rec{$field});
######## delicia
$output .= qq|<BR><input type=text name="$field" size="$db_form_len{$field}" maxlength="$db_lengths{$field}>"|;
$output .= "</TD></TR>";

Quote Reply
Re: [delicia] adding to select list In reply to
I think pehraps a combination of the two different methods combined will provide the results you are looking for.

Using the build_select_field_from_db sub to display the current selects wihin your database and then using sub beside_select_field to enable you to add additional select options t o the database.

Neither will store the value within your .cfg file for additional selections, but by using the build_select_field_from_db you will be able to display all the categories currently within your database.

I'm going to test this myself and see how it works.

Is that the setup you are attempting to use?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] adding to select list In reply to
This does work however to use it you would have to use the

print &build_select_field_from_db

which means you wouldn't have the ability to choose from options that don't have any matching records in the database already.

I got this to work by using in html_record_form:

<TR><TD width=350><$font><B>Category:</B></font> $reqpic</TD><TD>|; print &build_multiple_select_field("Category",$rec{'Category'}); print qq| <BR>|;
print &beside_select_field ("Category", "$rec{'Category'}", "$db_form_len{'Category'}");
print qq|</TD></TR>

Then adding sub beside_select_field to my db.cgi file.

Also be sure to add within sub parse_form in the db.cgi script.

After code:

if ($value eq "---") { next PAIR; }

add code:

unless ($value) { next PAIR; }

I had this working then modified the output of the field display a little and it kept causing category not entered errors. But I finally got it working using what I put above. Then I tested it several times and it was all working. So if you have problems when you adjust the display just keep playing with it ... the codes do work :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] adding to select list In reply to
i will try this later today. when i read the faq, i didn't think the beside_select_field routine actually added the text to the category field. thanks!