Gossamer Forum
Home : Products : DBMan : Customization :

build a select field

Quote Reply
build a select field
Hi All,
I wish to build a select field using the passwd file. Has this been done before, I have searched everywhere and found nothing on all forums. If this hasn't been done is it possible and how.

Many thanks for any help or pointers
Quote Reply
Re: [colinw] build a select field In reply to
Could you give a little more detail as to what you want to do?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] build a select field In reply to
Sorry,

I want to do is build a select field using a feild from the PASSWD file eg.USERID. I know it has been done using the DB records eg. build_select_field_from_db and using a particular DB field. I hope i'm make sence.

Thanks
Quote Reply
Re: [colinw] build a select field In reply to
It would just be a combination of sub build_select_field_from_db and the part that builds the select field in sub admin_display.
Code:
sub build_select_field_from_password {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $output);

$name || ($name = $column);

open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
push (@selectfields, $data[0]);
}

$output = qq|<SELECT NAME="$name"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";

return $output;
}
I'm not sure what use this would be unless you have a really huge database and it's taking too long to build the select field from the database file.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] build a select field In reply to
Thank JP this worked great and is what I was trying to do.
The reason I wanted this is I only want registered user to appear in this select field as I don't store the UserID in my DB.
Just one more q's, is there away to stop the "Admin" from appearing in the select field list.?

Again thanks for the help, you guys do a great job in providing the support for us beginners.
Quote Reply
Re: [colinw] build a select field In reply to
If you want the name "Admin" to not show up in the list, you would use

Code:
if ($data[0] ne 'Admin') {
push (@selectfields, $data[0]);
}

You can change that to any one username you wish. Be sure that the letter case is the same in the code as it is in the file.

If you don't want anyone with admin privileges to show up on the list, you would use
Code:
unless ($data[6]) {
push (@selectfields, $data[0]);
}

There's lots of things you can do with it. :-)

We're glad to help. All of us were newbies at some point.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] build a select field In reply to
Works great
thank you very very very much.