Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Dynamic checkbox list....

Quote Reply
Dynamic checkbox list....
Hi,

I'm trying to get a dynamic list of checkbox values shown on the users profile page (in my Edit_User_Profile plugin). So far, I have;

Code:
sub {
my $column = $_[0];
my $selected = $_[0];
my $table = $DB->table("Users");
my %hash;
my $i = 0;
my $names = $table->form_names->{$column};
my $vals = sort $table->form_values->{$column};
for my $val (@$vals) {
$hash{$val} = $names->[$i++];
}
my $html = $DB->html($table, $IN);
my $form = $html->select({
name => "$column",
values => \%hash,
multiple => 1,
value => $selected });
return $form;
}

However, this is making it into a SELECT box, rather than checkboxes. I've looked through the documentation again and again, but can't see what I'm doing wrong :(

Anyone got any ideas? Angelic

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Dynamic checkbox list.... In reply to
Did you try to use the $html->checkbox method?
Code:
sub {
my $column = $_[0];
my $selected = $_[0];
my $table = $DB->table("Users");
my %hash;
my $i = 0;
my $names = $table->form_names->{$column};
my $vals = sort $table->form_values->{$column};
for my $val (@$vals) {
$hash{$val} = $names->[$i++];
}
my $html = $DB->html($table, $IN);
my $form = $html->checkbox({
name => "$column",
values => \%hash,
multiple => 1,
value => $selected });
return $form;
}

Look at GT/SQL/Display/HTML.pm module, and find out if you pass in the correct input parameters, as I did not check this.
But this is the way you should do it.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Dynamic checkbox list.... In reply to
Nice one... thats where I was going wrong!

Finally managed to get it working right with;

field_checkbox_form =>
Code:
sub {
my $column = $_[0];
my $selected = $_[1];
my $table = $DB->table("Users");
my %hash;
my $i = 0;
my $names = $table->form_names->{$column};
my $vals = sort $table->form_values->{$column};
for my $val (@$vals) {
$hash{$val} = $names->[$i++];
}

my $html = $DB->html($table, $IN);
my $form = $html->checkbox({
name => "$column",
values => \%hash,
multiple => 1,
value => $selected });
return $form;
}

..and called with;

<%field_checkbox_form('Field_In_Question',$Field_In_Question)%>

Anyone who uses this.. .enjoy :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!