geektron has asked for the wisdom of the Perl Monks concerning the following question:

i've already hit SuperSearch and the CB. here's the problem:

i want to build a checkbox_group with CGI.pm's methods. easy enough:

$cgi->checkbox_group( -name => 'foo', -values => [ keys %hash ], -labels => \%hash );

the problem arises when i want to have a SUBSET of keys %hash, and not all the keys.

the problem doesn't seem to be in the subroutine i'm using to build the subset, but rather with CGI.pm itself. i just hard-coded one of the values, and it still didn't give me the label.

what i'm trying to do:

$cgi->checkbox_group( -name => 'foo', -values => $subset -labels => \%hash );
and it doesn't seem to work/ be supported. . . .

Replies are listed 'Best First'.
Re: CGI.pm, labels, and subsets
by geektron (Curate) on Feb 16, 2001 at 08:38 UTC
    update - more complete code ( i can't seem to edit the top-level node)::
    my %service_labels = ( display_external_host => 'ExternalHost', display_internal_host => 'InternalHost', display_virtual_host => 'VirtualHost', ); my $subset = [ 'ExternalHost' ]; $cgi->checkbox_group( -name => 'FOO', -values => $subset, -labels => \%service_labels );
    prints out this HTML:
    <INPUT TYPE="checkbox" NAME="FOO" VALUE="ExternalHost">ExternalHost <INPUT TYPE="checkbox" NAME="FOO" VALUE="VirtualHost">VirtualHost <INPUT TYPE="checkbox" NAME="FOO" VALUE="InternalHost">InternalHost

    what I expected ( or what I want );

    <INPUT TYPE="checkbox" NAME="FOO" VALUE="display_external_host">Extern +alHost

    which is what i'd get if i were to use  [ keys \%service_labels ] as my -values argument

      Try: my $subset = [ 'display_external_host' ]; In the arguments to checkbox_group, values refers to the values of the VALUE attributes in the HTML, not to the values in the labels hash. The values provided to the checkboxes should be the keys in the labels hash. How would CGI look up the label from the checkbox value otherwise?
        thanks to both merlyn and chipmunk. i ALWAYS get the key/value thing backwards w/ the -labels option.

        now i just need a clean way of getting $subset to have the KEYS to the hash. the contents of $subset are returned by another subroutine.