Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Checkboxes one more time.

Quote Reply
Checkboxes one more time.
Bummer, I thought we had worked out all the checkbox bugs, but I've come across yet another and I have no idea how to get around this one.

It has to do with adding as in add.cgi.

If I have a checkbox field and I've selected multiple items I can't get the add_error.html page to display those checkbox fields which have been checked.

check out www.nmculturenet.org/cgi-bin/webman/add.cgi?db=Artisans&ID=1

Go to: Visual Arts & Crafts, I only have web-based and woodworker/carver actived so don't waste you're time on anything else.

What happens is this.

I can make it so if 'web-based' is checked (only) that the add_error.html page gives me an error page with web-based checked, BUT if web-based AND Woodworker/carver are checked I get back NOTHING.

So.....What do I do?

I think this will be the last checkbox bug I come across!

Peace.

Kyle


[This message has been edited by klangan (edited February 15, 2000).]
Quote Reply
Re: Checkboxes one more time. In reply to
Hi Kyle

How does your template loo like?

give this a try

<input type="checkbox" name="carver" value="carver"<%if carver%>checked<%endif%>>

regards, Alexander
Quote Reply
Re: Checkboxes one more time. In reply to
Your going to need to make your checkboxes autogenerated. Add:

my $checkbox = $db->build_checkbox_field ('carver', $in->param('carver'));

and then add:

carver => $checkbox

to the template list. This will create the checkboxes with the appropriate ones filled out.

What Alex suggested will work with radio buttons (where you can only have one value), but not with checkboxes (where you can select multiple values.

Cheers,

Alex
Quote Reply
Re: Checkboxes one more time. In reply to
Hi Alex,

I've tried making the changes you suggested.

I did this (I had to change a few of the parameters to match mine)
Under:

# Validate the form input..
$rec = &cgi_to_hash($in);

#ADDED THIS
my $checkbox = $val->build_checkbox_field ('Visual_Arts_and_Crafts', $in->param('Visual_Arts_and_Crafts'));
#END ADD THIS

What I get is a list of all the proper fields, but only one item is checked regardless of how many I actually check.

Any ideas. Go here to see what I mean:
http://www.nmculturenet.org/cgi-bin/webman/add.cgi?db=Artisans&ID=1

I guess it has something to do with dbsql.pm, I find it very strange though that this DOES WORK in the admin area, but not in this section. This is what I'm passing to dbsql.pm:

my $checkbox = $val->build_checkbox_field ('Visual_Arts_and_Crafts', $in->param('Visual_Arts_and_Crafts'));

$val is defined as the appropriate Validate.def file. Again, it works, but the not all of the fields checked come back as checked.

Here is the code in dbsql.pm that accepts the input:

DBSQL.pm
sub build_checkbox_field {
# --------------------------------------------------------
# Builds a CHECKBOX field.

my ($self, $column, $values, $name) = @_;

${$self->{'db_checkbox_fields'}}{$column} or return "error building checkboxes: no checkboxes specified in config for field '$column'";
$name &#0124; &#0124;= $column;

my %values = map { $_ => 1 } split (/\,/, $values);
my @boxes = split (/,/, ${$self->{'db_checkbox_fields'}}{$column});
my $output = '';
foreach my $box (@boxes) {
$values{$box} ?
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$name" VALUE="$box" CHECKED> $box<br>\n!) :
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$name" VALUE="$box"> $box<br>\n!);
}
return $output;
}


Hope all is well in Beautiful Vancouver, I miss my visits to the city from here in Santa Fe.

Peace.

Kyle
Quote Reply
Re: Checkboxes one more time. In reply to
HI Alex,

I got it figured out:

instead of:

my $checkbox = $db->build_checkbox_field ('carver', $in->param('carver'));

say after
# Validate the form input..
$rec = &cgi_to_hash($in);

my $checkbox = $db->build_checkbox_field ('carver', ${$rec}{'carver'});

The needed info is located in $rec after it's gone through cgi_to_hash. Not before.

Peace.

Kyle