Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Re: [charly] Retrieving data from checkboxes

Quote Reply
Re: [charly] Retrieving data from checkboxes In reply to
Hi Charly,

You can use 'view_checked' template global below to determine which boxes have been checked:

sub {
my ($col, $val) = @_;
($col) or return;

my $tags = GT::Template->tags;
my $cols = $tags->{home}->{db}->cols;
($cols->{$col}->{form_type} =~ /checkbox/i ) or return;

my $f_values = $cols->{$col}->{form_values};
my $f_names = $cols->{$col}->{form_names};
my @values = split(/\n/, $val);

my @output;
foreach my $i (0..$#$f_names) {
my $checked = 0;
foreach my $v (@values) {
if ( $v eq $f_names->[$i] ) {
$checked = 1;
last;
}
}
push @output, { name => $f_values->[$i], value => $f_names->[$i], checked => $checked };
}

return { "loop_$col" => \@output };
}

Now, you can call it within your modify_form

<%view_checked('Pictures', $Pictures)%>
<%loop loop_Pictures%>
<input type="checkbox" name="Pictures" value="<%value%>" <%if checked%>checked<%endif%>><%Name%><br>
<%endif%>

Hope that helps.

TheStone.

B.
Subject Author Views Date
Thread Retrieving data from checkboxes charly 5138 Apr 15, 2003, 1:50 PM
Thread Re: [charly] Retrieving data from checkboxes
hennagaijin 4995 Apr 15, 2003, 8:41 PM
Thread Re: [hennagaijin] Retrieving data from checkboxes
charly 4975 Apr 15, 2003, 10:04 PM
Post Re: [charly] Retrieving data from checkboxes
hennagaijin 5002 Apr 16, 2003, 7:15 AM
Thread Re: [charly] Retrieving data from checkboxes
604 4944 Apr 16, 2003, 11:01 AM
Thread Re: [TheStone] Retrieving data from checkboxes
charly 4919 Apr 16, 2003, 12:05 PM
Thread Re: [charly] Retrieving data from checkboxes
604 4946 Apr 16, 2003, 12:57 PM
Post Re: [TheStone] Retrieving data from checkboxes
charly 4890 Apr 16, 2003, 10:45 PM