Gossamer Forum
Home : Products : Gossamer Links : Discussions :

checkbox form values

Quote Reply
checkbox form values
I have checkboxes on my and form. when a user tries to modify a listing how do i get the saved checkbox values and recheck the boxes on the modify page. I have tried the following:

sub {

my $tags = shift;
my $amen = $tags->{amenities};
my @formvalues = $DB->table('Links')->cols->{'amenities'}->{form_values};
my @values = split(/\n+/,$amen);
my $valueHash = {};
my $ele = "<tr>";
my $count = 0;

foreach my $element (@values) {
$valueHash {$element} = $count ;
$count++;
}
$count=0;
foreach my $element (@formvalues) {
$ele .= "<td><input name='amenities' type='checkbox' value='$element'";
if( exists( $valueHash{$element}) ) {
$ele .= " checked ";
}

$ele .= ">$element<br></td>";
$count++;
if($count%4 == 0){
$ele .="</tr><tr>";
}
}
return $ele;
}



and i keep getting:

Global symbol "%valueHash" requires explicit package name at (eval 24) line 12.


A fatal error has occured:GT::Config (26102): Unable to compile 'checkAmen' in file '/home/sites/site31/web/cgi-bin/admin/templates/av/globals.txt': at /home/sites/site31/web/cgi-bin/admin/GT/Template.pm line 461
Quote Reply
Re: [vanhut] checkbox form values In reply to
ok i figured out that i needed to change:

$valueHash{$element}

to

$valueHash->{$element}

but now all i get is one checkbox with ARRAY(0x84d3a60) next to it:

ARRAY(0x84d3a60)

help please
Quote Reply
Re: [vanhut] checkbox form values In reply to
It is an array reference, you can get the values using:

$valueHash->{$element}->[element_number];

or all:

@{$valueHash->{$element}}

Last edited by:

Paul: Jul 15, 2002, 1:27 PM
Quote Reply
Re: [Paul] checkbox form values In reply to
i never use the element number. I'm using the hash as a way to hold the checkboxes that have been checked. In my form i have about 70 checkboxes, all with the same name but different values. the user checks on those that apply to his listing. ...

so i am trying to take all the checkbox values and display checkboxes while at the same time seeing if the box was origionally checked by the user.

for some reason

my @formvalues = $DB->table('Links')->cols->{'amenities'}->{form_values};


is not working because the only element in the has is

$valueHash->{'ARRAY(0x84d3b68)'} = 0
Quote Reply
Re: [vanhut] checkbox form values In reply to
Try:

my @formvalues = @{$DB->table('Links')->cols->{'amenities'}->{form_values}};
Quote Reply
Re: [Paul] checkbox form values In reply to
thanks it's working now... here is the code if anyone is interested

sub {

my $tags = shift;
my $amen = $tags->{amenities};
my @formvalues = @{$DB->table('Links')->cols->{'amenities'}->{form_values}};
my @values = split(/\n+/,$amen);
my $valueHash = {};
my $ele = "<tr>";
my $count = 0;

foreach my $element (@values) {
$valueHash->{$element} = $count ;
$count++;
}
$count=0;
foreach my $element (@formvalues) {
$ele .= "<td><input name='amenities' type='checkbox' value='$element'";
if( exists( $valueHash->{$element}) ) {
$ele .= " checked ";
}

$ele .= ">$element<br></td>";
$count++;
if($count%4 == 0){
$ele .="</tr><tr>";
}
}
return $ele;
}
Quote Reply
Re: [vanhut] checkbox form values In reply to
Just a thought...you may want to change that to:

Code:
my $list = $DB->table('Links')->cols->{'amenities'}->{form_values};
my @formvalues = ref $list eq 'ARRAY' ? @{$list} : $list;

...as you need to verify what is returned.

Last edited by:

Paul: Jul 15, 2002, 3:21 PM