Home : Products : DBMan : Customization :

Products: DBMan: Customization: Re: [jmortimer] External Text File for Drop-down Box Options: Edit Log

Here is the list of edits for this post
Re: [jmortimer] External Text File for Drop-down Box Options
It wouldn't be hard to write the code to do what you want, but there are easier ways to do it.

You don't need to change the permissions on the .cfg file when you upload it a second time. Once the file has permission, it's set, as long as you keep the same name. Also, you probably don't have to change the permission for the .cfg file anyway. The permission that's needed is 644 : rw- r-- r-- which is the default permission given to all files on every server I've used. It is possible that yours is different, though.

The easiest way to make changes to the .cfg file would be to install the Gossamer Threads Fileman utility. It's completely free and will allow you to edit your files online. No uploading necessary. Very easy.

If you still want to use an external file for the select field options, the best thing would be to have a separate file for each select field. So, if you have a select field called "Type", you would want to have a text file called "Type.txt". The contents of the file would just be the options for that field, one per line. Put the files in the same directory as DBMan.

Add the following to db.cgi:

Code:

sub build_select_field_from_file {
my ($column, $value) = @_;
my (@selectfields, $output);
$fieldfile = $db_script_path . "/" . $column . ".txt";
open (FIELD, "<$fieldfile") or &cgierr("error in building field. unable to open file: $fieldfile.\nReason: $!");
if ($db_use_flock) {
flock(FIELD, 2) or &cgierr("unable to get exclusive lock on $fieldfile.\nReason: $!");
}
LINE: while (<FIELD>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
push (@selectfields, $line);
}
close FIELD; # automatically removes file lock
$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (@selectfields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}



Where you want to print out your select field use print &build_select_field_from_file ("Fieldname", "$rec{'Fieldname'}");


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Dec 23, 2006, 3:11 PM

Edit Log: