checkbox_group => CGI, Perl

Hi,

In my cgi script(written in Perl using cgi.pm) i have a checkbox and i want all the items to be checked. Here is what i use:

checkbox_group(-name=>'studenten_in_groep', -values=>\@member_keys, -defaults=>\@member_keys, -labels=>\%temp_members, -columns=>2),

But no boxes are checked...

Ideas anyone??

Tine

I think you need to actually tell it that you want the checkboxes checked.

I know checkbox_group() creates a list of checkboxes, but I don't think it checks them by default.

And when you create a single checkbox, you use syntax like

checkbox(-name=>'checkboxName',
         -checked=>'checked',
         -value=>'someNalue',
         -label=>'someLabel');

so I'm guessing you'd want to use something like

checkbox_group(-name=>'studenten_in_groep',
               -values=>\@member_keys,
               -defaults=>\@member_keys,
               -labels=>\%temp_members,
               -checked=>'checked',
               -columns=>2);

but this is untested so I'm not sure...

Ok, scratch that I think. :stuck_out_tongue:

See this site for an example: http://stein.cshl.org/WWW/software/CGI/\#checkbox_group

Named parameter style
print $query->checkbox_group(-name=>'group_name',
                             -values=>['eenie','meenie','minie','moe'],
                             -default=>['eenie','moe'],
                             -linebreak=>'true',
                             -labels=>\%labels);

This is the same example that i have used to form my script.
But in stead of default=>['eenie','moe'] i use an array, wich should have the same effect.
But it doesn't!
Even if i write out a few values that are in the array in the way that it is done in the example it still doesn't work..

Could you post your code exactly as you have it in your script?

The code in my first message is what i use;

checkbox_group(-name=>'studenten_in_groep',
-values=>\@member_keys,
-defaults=>\@member_keys,
-labels=>\%temp_members,
-columns=>2),

This code shows a group of checkboxes that are not checked. I can leave the defaults line out and it does exactly the same.
The values and the defaults have the same array, so i think it should check every box...

Are the values actually showing up correctly in the html code that's created?

Is -defaults a typo? There shouldn't be an "s" on the end...

I have seen examples with and without an 's' and tried both, but still no luck.
I looked at the source code and the values are correct.

try removeing the array referance and just use a flat out scalar.

i know the array ref can be used as a scalar but do it the long way first then try and shorten it.

in my CGI programming with Perl book i only see this for checkboxes.

<INPUT TYPE="checkbox" NAME="Toppings" VALUE="onion" CHECKED>Onion<BR>

I have tried using a scalar, but still no luck..

check out the docs for checkbox_group @ http://www.perldoc.com/perl5.8.0/lib/CGI.html\#CREATING-A-GROUP-OF-RELATED-CHECKBOXES

what is the exact error you get when you run your CGI script?

check your apache/logs/error.log file.

There is no error!

if its not working there has to be an error. OR.... your not populateing the array. put in a little forloop (right befor where your checkbox_group section is to print out the contents of your array ref.

do you have warnings turned on?

btw is this a typo on purpose?
'studenten_in_groep'

lastly use the code brackets and past your perl script.

The array i use for defaults is the same as the array for values. So i am sure that it is populated..

Warnings turned on, but nothing about this problem. The defaults option seems to be ignored completely. I can give it any value i want, either in a scalar or an array reference, it doesn't seem to do anything.

"studenten_in_groep" is just the name of the group.

What do you mean with that last comment?

use this.

checkbox_group(
       -name=>'studenten_in_groep',
       -values=>[@member_keys],
       -defaults=>[@member_keys],
       -labels=>\%temp_members,
       -columns=>2),

i got it working just by looking at the examples in the docs for cgi.pm

1) your not useing referances correctly
2) dont misspell in your code.

A reference to an array is allways done using \@array, not [@array], isn't it?
Where am i misspelling?

I copied and pasted your code, but still the same.

is this homework? or a classroom exersize?

your missspelling: studenten_in_groep
it should be "student_in_group" it makes it much clearer when reading your code.

then you would have to send me your entire cgi program.

send it as a zip file.

the are for the parameters. they are used to group the values needed.

a referance to an array:
@bob=("eenie", "minie");
$joe=\@bob;

for (@$joe) { print "ArraryRef Items: $_ \n" };
ArraryRef Items: eenie
ArraryRef Items: minie

In a previous answer you give me a piece of code to use;
checkbox_group(
-name=>'studenten_in_groep',
-values=>[@member_keys],
-defaults=>[@member_keys],
-labels=>\%temp_members,
-columns=>2),
You tell me i use references wrong, but in this code for an array reference you use [@member_keys]. That confused me, because it is not a reference!
I wasn't asking you how a reference to an array works, i was questioning your use of @member_keys in your code..

from cpan about checkbox_group:

Here they give an example of using the array ref the way i use it..

What makes you think this is homework??

studenten is dutch for students and groep is dutch for group, so it is not misspelling, it is just a different language than english!!

I finally found a way to solve this problem...

I give the checkbox_group a value before it is printed, so now i use:

param('studenten_in_groep' => @member_keys);

checkbox_group(-name=>'studenten_in_groep', -values=>\@member_keys, -labels=>\%temp_members, -columns=>2),