Gossamer Forum
Home : Products : DBMan : Installation :

Multiple checkbox selection assistance needed

Quote Reply
Multiple checkbox selection assistance needed
I'm having a problem that seems to be common, but I can't find a suitable solution after looking thru past posts, unless I simply missed it.

Since adding the upload mod, on my checkbox field, only the first selection is being added with the record and all others in the field are ignored. I've deleted the line:

unless ($value) { next PAIR; }

in the parse_form sub as suggested on another post, but it doesn't solve the problem.

The parse_form code looks like this:
my (%in);
my ($buffer, $pair, $name, $value);
PAIR: foreach $name ($query->param()) {
$value = $query->param("$name");
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($value eq "---") { next PAIR; }
(exists $in{$name}) ?
($in{$name} .= "~~$value") :
($in{$name} = $value);
}
return %in;
}

My cfg code:

Amenities => [14, 'alpha', 0, 255, 0, '', ''],

and

%db_checkbox_fields = ( Amenities => 'Fireplace,Deck,Pool,Patio,Fenced Yard,1 Car Garage,2 Car Garage,Carport,Refrigerator,Microwave,Range/Oven,Dishwasher,Insulated Windows,Hardwood Floors,Ceramic Tiles,Ceiling Fans,Termite Bond,Basement,Attic,Stor. Bldg.',

Photo => 'Yes'

);

In db.cgi build_checkbox_field:

my @names = split (/,/, $db_checkbox_fields{$column});
my @values = split (/\Q$db_delim\E/, $values);
my ($name, $output);
foreach $name (@names) {
(grep $_ eq $name, @values) ?
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$name" CHECKED> $name\n!) :
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$name"> $name\n!);
}
return $output;

In build-html-record_form (I didn't change any of this from the original DBMAN code):

elsif ($db_checkbox_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_checkbox_field ($field, $rec{$field}) . "</td></tr>"; }

Then, in html_record_form:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Other Amenities:</FONT></TD>

<TD VALIGN="TOP"> <font face="Verdana, Arial, Helvetica" Size=1 Color=#000000>&nbsp;|; print &build_checkbox_field ("Amenities", "$rec{'Amenities'}"); print qq|</TD></TR>

and in html_record:

<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Other Amenities:</FONT></TD>

<TD>&nbsp;<$font>$rec{'Amenities'}</Font></TD></TR>

The Amenities showed up fine (Fireplace|Carport|Basement, etc.) before I installed the upload mod, when I had only the one checkbox field.

Now, since I've added the "Photo" field necessary for the uploading process, it adds only the first Amenity that's checked, whether I upload a photo or not.

What am I missing? Please explain in simple terms, since I'm not well-versed in all this.
Quote Reply
Re: [smithT] Multiple checkbox selection assistance needed In reply to
Checkboxes are, by nature, not multiple select items. They are an 'on/off' switches. Either it is or it isn't. You'll need to make a field for each of your checkbox fields.

Please note that each checkbox used must also have a corresponding field defined for your database. This will allow people to be able to search for more than one of the options.

You can learn more about setting them up by visiting JPDeni's DBMan tutorial at: http://www.jpdeni.com/dbman/

or visit the FAQ noted below.



Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple checkbox selection assistance needed In reply to
Okay, let me see if I understand what you're saying.

I need to break down field_name Amenities as such?:
Fireplace => [14, 'alpha', 0, 255, 0, '', ''],
Deck => [15, 'alpha', 0, 255, 0, '', ''],
Pool => [16, 'alpha', 0, 255, 0, '', ''],

and then set up by checkboxes as:
%db_checkbox_fields = ( 'Fireplace ='yes',
Deck='yes',
Pool='yes', ... and so on?

And then list each amenity (fireplace, deck, pool, etc.) individually in my html form definitions?

Can I list them all in one TD on the html so that my display form doesn't go on for pages and pages? for example:
<TR>
<TD ALIGN="Right" VALIGN="TOP"><$font>Other Amenities:</FONT></TD>
<TD VALIGN="TOP"> &nbsp;|;
print &build_checkbox_field ("Fireplace", "$rec{'Fireplace'}");
print &build_checkbox_field ("Deck", "$rec{'Deck'}");
print &build_checkbox_field ("Pool", "$rec{'Pool'}");
print qq|</TD></TR>

If you answer in the affirmative to all of the above, then I'll get right on it. If I've misunderstood your instructions, please tell me.

But I have one question ...
why did I previously get a list of the amenities formatted so nicely if they were set up incorrectly all this time?

Quote Reply
Re: [smithT] Multiple checkbox selection assistance needed In reply to
Quote:
Can I list them all in one TD on the html so that my display form doesn't go on for pages and pages?
Yep. May need to throw in some <BR> tags depending on whether you want them in column or row (could also accomplish same thing with <TR> or <TD> tags as well)


Quote:
why did I previously get a list of the amenities formatted so nicely if they were set up incorrectly all this time?
Sometimes you *can* do things, but probably shouldn't or it'll cause problems later on.


PS:
Quote:
%db_checkbox_fields = ( 'Fireplace ='yes',
Deck='yes',
Pool='yes', ... and so on?

Just don't forget to take out that last comma on your last item.

Also, if you want to get fancy you can copy the build_select or build_whatever subroutine in db.cgi and modify it and give it a name called build_select_two or something and then call it like you did above. This is good for adding <BR> to radio buttons, etc.

Quote Reply
Re: [Watts] Multiple checkbox selection assistance needed In reply to
Thanks. I changed everything and it's working okay now. One thing I did wrong in my example was in the cfg file, for my checkbox fields, I had to specify 'Fireplace' = 'Fireplace', etc. With the 'yes' in there, all I got was a bunch of yesses and nothing else.Smile

Slowly but surely, I'm getting the hang of this stuff.