in reply to CGI.pm, labels, and subsets

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

Replies are listed 'Best First'.
Re: Re: CGI.pm, labels, and subsets
by chipmunk (Parson) on Feb 16, 2001 at 08:47 UTC
    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.

Re: Re: CGI.pm, labels, and subsets
by merlyn (Sage) on Feb 16, 2001 at 08:45 UTC