Gossamer Forum
Home : Products : DBMan : Customization :

dynamically add fields to default.cfg?

Quote Reply
dynamically add fields to default.cfg?
Is there any way possible that when a new user is added, a new category added by a user, etc, to automatically have that new username, category, etc. added to the appropriate drop-down list in default.cfg without having to go in and do it manually?

Just wondering...
Quote Reply
Re: dynamically add fields to default.cfg? In reply to
I know this is possible as JPD has just used in in the DMan mod database, see today's post. Hopefully by bringing this thread to the top someone will help you (I'd like this too!)
Quote Reply
Re: dynamically add fields to default.cfg? In reply to
Well, yes and no.

Here's what you can do. You can have a text field where users can enter anything they want. And you can have a separate form for searching that lists all the values of a given field within a select list. Is this what you want?


------------------
JPD





Quote Reply
Re: dynamically add fields to default.cfg? In reply to
I can't answer for mrmeat, but I would be interested in the drop-down list box that contains only values already submitted. I currently am working with a 'countries' box, and to have all the countries, when most haven't got entries yet is wasteful!
Quote Reply
Re: dynamically add fields to default.cfg? In reply to
JP,

Not really - I guess I should have been more exact in what I want to do - I have a resume / job database and would like to give the admin (not me) the ability to add values to drop down lists (IE Job Industry) themselves without having to edit the default.cfg file. Any way to do this?
Quote Reply
Re: dynamically add fields to default.cfg? In reply to
This may already be in your script, even though it is not mentioned anywhere. Open db.cgi and do a search for

sub build_select_field_from_db

If it's there, ignore the next part of this and go to the end of this message to find out how to use it.

If it's not there, add the following subroutine to db.cgi:

Code:
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 or ($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;
}

To use this, in the place where you want it to print the select field, enter

Code:
|;print &build_select_field_from_db("FieldName","$rec{'FieldName'}"); print qq|

replacing FieldName with the name of the field you want to have in your select list.


------------------
JPD