Gossamer Forum
Home : Products : DBMan : Installation :

Installing checkboxes to provide item1|item2|item3 etc

Quote Reply
Installing checkboxes to provide item1|item2|item3 etc
When doing a new install and after using JPD's configurator (to get it right!), I set up a checkbox field with the options of: item1, item2, item3, item4, item5.

Initally it worked fine. While some records would show: item1|item3 as desired and others would show: item3|item4|item5, etc as desired, this enabled users to do a field serch and find the right records.

Now I find my checkbox is no longer adding the multiple variants as required: If I chose in 'add' or 'modify' a record and choose the options: item2, item3, item5 ... it will just record/show the first one ONLY (ie: item2).

Here is some of my code:

Indefault.cfg

'Dishes' => [ 7, 'alpha', 0, 255, 0, '', ''],

..the comma is fine at the end - it is not the last definition

'Cuisine' => 'Australian,Mediterranean,Chinese,Japanese,Thai,Indian,French,Italian, Greek,Scottish',

..the comma is fine at the end - it is not the last checkbox option.

html.pl

sub html_record_form {

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Dishes:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"><$font_sm>&nbsp;|; print &build_checkbox_field("Dishes",$rec{'Dishes'}); print qq|</TD></TR>


sub html_record {

<tr><TD vAlign=top colspan="2"><$font_color>Dishes:</font>&nbsp;<$font>$rec{'Dishes'}</FONT><br></TD></TR>


Now in Alex's original and uncustomised program downloaded, I can add 'No' to this checkbox field (it originally just said 'Yes' only) .....

%db_checkbox_fields = ( Popular => 'Yes,No' );

... and in the 'add' or 'modify' areas, can then choose YES as well as NO with a result recorded as:

Popular: Yes|No

This is what I want - so what simple little thing am I overlooking to have my multiple choice checkbox record 'multiple' options in the database.
Quote Reply
Re: [chasau] Installing checkboxes to provide item1|item2|item3 etc In reply to
Found the answer .... sort of.

After I posted, I wondered if it had anything to do with db.cgi So I uploaded my version of db.cgi with JPDs 'pic uploader' and the 'lost password' mods.

Result: Popular: Yes

.... the Yes|No has disappeared!!

So uploaded the original uncustomised db.cgi and the Yes|No appeared again.

The db.cgi I have with these two mods is working well with a database I am building so the file seams OK. However, to my novice eye, it appears there may be something in these mods in db.cgi that is causing the drama.

Have uploaded db.cgi (with the mods) to http://www.auscity.com/dbman as a text file called db_cgi.txt

Would realy appreciate an interested person going over it to see if the problam can be found.
Quote Reply
Re: [chasau] Installing checkboxes to provide item1|item2|item3 etc In reply to
nm... I misread the problem you were having and don't use the autogenerate myself. Sorry.

Last edited by:

oldmoney: May 16, 2002, 8:24 AM
Quote Reply
Re: [chasau] Installing checkboxes to provide item1|item2|item3 etc In reply to
Are you sure you want checkboxes? As you describe what you are doing it seems you are wanted to have a multiple select field, am I correct?

If you use checkboxes you would need to define each checkbox or option as a field within your database.

If you are wanting to have a multiple select field there is an additional mod you will need to install to have it recognize the multiple selections.

The setup we would need to see is your .cfg file, not the db.cgi file.

Please visit the FAQ and search in the section "Fields" or search for "Multiple Select" and you will find the mod. It should also be available from JPDeni's site http://www.jpdeni.com/dbman/ or in the Resource Center here on GT.

There was also a recent post with the sub to add to your db.cgi file. Search the forum for "build_multiple_select"

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Installing checkboxes to provide item1|item2|item3 etc In reply to
Thanks for the input to my problem LoisC.

I can see one solution is the use the multiple select box as you have suggested but I have always had a resistance to this because I fear newbie web users will not know what a CTL key is.

The other solution as you stated is in making each choice a separate field with its own checkbox but that involves having to add so much code and 'if' statements to achieve the selected options being displayed on one line without spaces (for thoise options/fields that were not checked).

Wouldn't it be great if after adding the upload mod in db.cgi to have ONE simple multi-choice checkbox field and then to use the mod in your FAQ ( http://webmagic.hypermart.net/dbman/db/dbfaq.cgi?db=dbmanfaq&uid=buster.102158034211993&sb=7&so=ascend&Validated=Yes&Category=Fields&view_records=1&nh=89&mh=1 ) ... to change the '|' into ','.

I would still really like to be able to develop search criteria such as:

Cruise: [ ]Australian [ ] Mediteranian [ ] Greek [ ] Thai, etc

Dishes: [ ] Steaks [ ] Hamburgers [ ] Smorgasbord [ ] Bakery, etc

... and then have results (for each field) show up on (their own) one line such as ...

Cruise: Australian, Mediteranean, Thai, etc

Dishes: Steaks, Hamburgers, Seafood, Stir Frys, etc.

I think I had better take this discussion over to the 'Modifications' forum and give it the title of "Modifying checkboxes to provide item1|item2|item3 etc".
Quote Reply
Re: [chasau] Installing checkboxes to provide item1|item2|item3 etc In reply to
OK, if that's what you're after, you can a use JavaScript onSubmit handler to build a hidden (the actual) field when submitted, making checkboxes act like a multi-select field.

It would look something like this:

Code:
<SCRIPT LANGUAGE="JavaScript"><!-- Begin
function formCheck() {
var output;
output = "";
for (var i = 0; i < 4; i++) {
// CHANGE i < 4 to # of checboxes you have
box = eval("document.catform.c" + i);
if (box.checked == true) {
output = output + box.value + "~";
}
}
document.catform.MyRealCategory.value = output;
}
// End --></script>

<FORM action="$db_script_url" method="GET"
name="catform" onSubmit="return formCheck();">

<input type=hidden name="db" value="yourDB">
<input type=hidden name="uid" value="$db_uid">
<INPUT TYPE=HIDDEN NAME="MyRealCategory" VALUE="">
<!-- THIS IS THE FIELD WE ARE ACTUALLY SAVING -->

<INPUT TYPE=CHECKBOX NAME=c0 VALUE="Greek">Greek
<INPUT TYPE=CHECKBOX NAME=c1 VALUE="Italian">Italian
<INPUT TYPE=CHECKBOX NAME=c2 VALUE="Thai">Thai
<INPUT TYPE=CHECKBOX NAME=c3 VALUE="Australian">Australian
<!-- NOTE THAT THESE CHECKBOXES are SEQUENTIALLY NUMBERED
STARTING AT 0 AND *NOT* DEFINED, DBMAN WILL IGNORE THEM -->
<INPUT TYPE=Submit VALUE="Submit">
</FORM>

JavaScript is your friend... until it decides not to be. Tongue

Last edited by:

oldmoney: May 16, 2002, 2:18 PM
Quote Reply
Re: [LoisC] Installing checkboxes to provide item1|item2|item3 etc In reply to
LoisC,

Just to get back to you about using the multiple select field instead of using checkboxes, tried it and it still only enters one value into the database (instead of the 3 or 4 selected) when I am using db.cgi with the upload mod. Without the upload mod, multiple select fields work well just as do checkboxes.

The problem is using db.cgi with the upload mod installed.

Have searched the forum endlessly for an answer and finding there are many others with the same problem.

Guess it means separate fields for each of the options until someone can write a patch or whatever for db.cgi with the upload mod installed.

Thanks for your assistance anyway - much appreciated.
Quote Reply
Re: [chasau] Installing checkboxes to provide item1|item2|item3 etc In reply to
When you are referring to the image upload mod, I'm wondering if you installed this to be able to upload images for each record?

I can't help but think you assumed this would provide other multiple selection type options.

To have the multiple select mod work you need to add the sub to your db.cgi file and then modify the call within your html_record_form according to the instructions provided.

Yes, others have had problems using both the image upload and multiple select mod but I believe there was a javascript solution provided. I'm pretty sure it was added to the FAQ.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Installing checkboxes to provide item1|item2|item3 etc In reply to
Lois. Yes I installed the upload mod just to be able to upload one pic for each record. I didn't have expectations that the mod would do anything else.

Regarding the multiple select mod, I added that to db.cgi and made the necessary changes in html.pl It worked like it should using db.cgi without the upload mode but not with db.cgi with the upload mod. This is also what happened with the checkboxes.

Oldmoney (thankyou) has also kindly provided a java solution but at this stage, am resistant to go down that track because I would be playing with something I know little about!. Instead what I did was create another 20 individual checkbox fields with a single value for each one. To provide a division between each checkbox 'value' when search results show these on a single line, I added a '·' . So value="·Australian" , etc

This then provides the following result:

Cuisine: ·Australian ·Malaysian ·Indian ·Japanese , etc.

It looks quite presentable on the screen and provides much the same as the initial result I was looking for. The only difference was another two hours required to set up and an addition 20 individual values throughtout all the scripts rather than 15mins using

Cuisine => 'Australian,Malaysian,etc',

If it is of any help for others who have found this forum entry and have had the same problem and given LoisC and Oldmoney have taken the time to help, here is the exact code I ended up using:

default.cfg

# Database Definition
# --------------------------------------------------------
# Definition of your database. Format is
# field_name => ['position', 'field_type', 'form-length', 'maxlength', 'not_null', 'default', 'valid_expr']

%db_def = (
'ID' => [ 0, 'numer', 20, 28, 1, '', ''],
'User' => [ 1, 'alpha', 50, 28, 0, '', ''],
'State' => [ 2, 'alpha', 0, 255, 1, '', ''],
'Region' => [ 3, 'alpha', 0, 255, 1, '', ''],
'Local Region' => [ 4, 'alpha', 0, 255, 1, '', ''],
'Town' => [ 5, 'alpha', 0, 255, 1, '', ''],
'Australian' => [ 6, 'alpha', 0, 255, 0, '', ''],
'Mediterranean' => [ 7, 'alpha', 0, 255, 0, '', ''],
'Chinese' => [ 8, 'alpha', 0, 255, 0, '', ''],
'Japanese' => [ 9, 'alpha', 0, 255, 0, '', ''],
'Thai' => [ 10, 'alpha', 0, 255, 0, '', ''],
'Indian' => [ 11, 'alpha', 0, 255, 0, '', ''],
'French' => [ 12, 'alpha', 0, 255, 0, '', ''],
'Italian' => [ 13, 'alpha', 0, 255, 0, '', ''],
'Greek' => [ 14, 'alpha', 0, 255, 0, '', ''],
'b' => [ 15, 'alpha', 0, 255, 0, '', ''],
'c' => [ 16, 'alpha', 0, 255, 0, '', ''],
'd' => [ 17, 'alpha', 0, 255, 0, '', ''],
'e' => [ 18, 'alpha', 0, 255, 0, '', ''],
'Steaks' => [ 19, 'alpha', 0, 255, 0, '', ''],
'Vegetarian' => [ 20, 'alpha', 0, 255, 0, '', ''],
'Smorgasboard/Buffet' => [ 21, 'alpha', 0, 255, 0, '', ''],
'Poultry' => [ 22, 'alpha', 0, 255, 0, '', ''],
'Seafood' => [ 23, 'alpha', 0, 255, 0, '', ''],
'Pasta' => [ 24, 'alpha', 0, 255, 0, '', ''],
'Pizza' => [ 25, 'alpha', 0, 255, 0, '', ''],
'Bakery/Sandwiches' => [ 26, 'alpha', 0, 255, 0, '', ''],
'Stir Frys' => [ 28, 'alpha', 0, 255, 0, '', ''],
'h' => [ 29, 'alpha', 0, 255, 0, '', ''],
'i' => [ 30, 'alpha', 0, 255, 0, '', ''],
'Licenced' => [ 31, 'alpha', 0, 16, 1, '', ''],
'Licence Type' => [ 32, 'alpha', 0, 60, 0, '', ''],
'Business name' => [33, 'alpha', 20, 255, 1, '', ''],
'Address' => [34, 'alpha', 20, 255, 1, '', ''],
'Phone' => [35, 'alpha', 20, 255, 1, '', ''],
'Hours' => [36, 'alpha', 0, 255, 0, '', ''],
'Email' => [37, 'alpha', 20, 255, 0, '', '.+@.+..+'],
'Web' => [38, 'alpha', 20, 255, 0, '', '^http://'],
'Location' => [39, 'alpha', 0, 255, 0, 'CBD', ''],
'Overview' => [40, 'alpha', 20, 255, 0, '', ''],
'Details' => [41, 'alpha', 20, 255, 0, '', ''],
'BusP' => [42, 'numer', 0, 8, 0, '', ''],
'Date' => [43, 'date', 20, 255, 0, &get_date(), ''],
'Post Code' => [44, 'alpha', 1, 255, 1, '3280', ''],
'Special Offer' => [45, 'alpha', 20, 255, 0, '', ''],
'Breakfast' => [46, 'alpha', 20, 255, 0, '', ''],
'Lunch' => [47, 'alpha', 20, 255, 0, '', ''],
'Dinner' => [48, 'alpha', 20, 255, 0, '', ''],
'Late Supper' => [49, 'alpha', 20, 255, 0, '', ''],
'Graphic' => [50, 'alpha' ,0, 3, 0,'', 'Yes']
);


# Checkbox fields. Field name => Checkbox value.
%db_checkbox_fields = (
'Breakfast' => '·Breakfast',
'Lunch' => '·Lunch',
'Dinner' => '·Dinner',
'Late Supper' => '·Late Supper',
'Australian' => '·Australian',
'Mediterranean' => '·Mediterranean',
'Chinese' => '·Chinese',
'Japanese' => '·Japanese',
'Thai' => '·Thai',
'Indian' => '·Indian',
'French' => '·French',
'Italian' => '·Italian',
'Greek' => '·Greek',
'Steaks' => '·Steaks',
'Vegetarian' => '·Vegetarian',
'Smorgasboard/Buffet' => '·Smorgasboard/Buffet',
'Poultry' => '·Poultry',
'Seafood' => '·Seafood',
'Pasta' => '·Pasta',
'Pizza' => '·Pizza',
'Bakery/Sandwiches' => '·Bakery/Sandwiches',
'Stir Frys' => '·Stir Frys',
'b' => '·b',
'c' => '·c',
'd' => '·d',
'h' => '·h',
'i' => '·i',
'Graphic' => 'Yes'
);


html.pl

sub html_record_form

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Cuisine:</FONT></TD>

<TD VALIGN="TOP" WIDTH="475"><$font_sm>
&nbsp;|; print &build_checkbox_field("Australian",$rec{'Australian'}); print qq|
&nbsp;|; print &build_checkbox_field("Mediterranean",$rec{'Mediterranean'}); print qq|
&nbsp;|; print &build_checkbox_field("Chinese",$rec{'Chinese'}); print qq|
&nbsp;|; print &build_checkbox_field("Japanese",$rec{'Japanese'}); print qq|
&nbsp;|; print &build_checkbox_field("Thai",$rec{'Thai'}); print qq|
&nbsp;|; print &build_checkbox_field("Indian",$rec{'Indian'}); print qq|
&nbsp;|; print &build_checkbox_field("French",$rec{'French'}); print qq|
&nbsp;|; print &build_checkbox_field("Italian",$rec{'Italian'}); print qq|
&nbsp;|; print &build_checkbox_field("Greek",$rec{'Greek'}); print qq|
</font></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Dishes:</FONT></TD>

<TD VALIGN="TOP" WIDTH="475"><$font_sm>
&nbsp;|; print &build_checkbox_field("Steaks",$rec{'Steaks'}); print qq|
&nbsp;|; print &build_checkbox_field("Vegetarian",$rec{'Vegetarian'}); print qq|
&nbsp;|; print &build_checkbox_field("Smorgasboard/Buffet",$rec{'Smorgasboard/Buffet'}); print qq|
&nbsp;|; print &build_checkbox_field("Poultry",$rec{'Poultry'}); print qq|
&nbsp;|; print &build_checkbox_field("Seafood",$rec{'Seafood'}); print qq|
&nbsp;|; print &build_checkbox_field("Pasta",$rec{'Pasta'}); print qq|
&nbsp;|; print &build_checkbox_field("Pizza",$rec{'Pizza'}); print qq|
&nbsp;|; print &build_checkbox_field("Bakery/Sandwiches",$rec{'Bakery/Sandwiches'}); print qq|
&nbsp;|; print &build_checkbox_field("Stir Frys",$rec{'Stir Frys'}); print qq|
</font></TD></TR>


sub html_record

<tr><TD vAlign=top colspan="2"><$font_color>Cuisine:</font>&nbsp;<$font> $rec{'Australian'} $rec{'Mediterranean'} $rec{'Chinese'} $rec{'Japanese'} $rec{'Thai'} $rec{'Indian'} $rec{'French'} $rec{'Italian'} $rec{'Greek'}</FONT><br></TD></TR>