http://qs321.pair.com?node_id=383186

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

Morning fellow monks,

Im having troubles with displaying the formatting of the labels in a checkbox_group.

Basically what im trying to achieve is to create a horizontal list of check boxes, the labels for these checkboxes will vary and so must the formatting.

As shown in the code below...

... @the_list = ("1","2","3","4"); foreach $bit (@the_list) { $the_labels{$bit} = $bit . "label1" . "description"; } return (table({-border=>'0',-width=>'100%'}, start_form({-action=>'./somescript.cgi', -method=>'POST'}), TR,td,checkbox_group(-name=>'the_group',-values=>[@the_list],-linebrea +k=>'true',-labels=>\%the_labels), submit(-name=>'submit',-value=>'submit'), end_form() ) );

the problem i have is when i try to place any tabs or extra spaces in the description bits for $the_labels{$bit} they are removed when the routine is returned and displayed on the web page.
I've already tried placing extra spaces in the description and also placing "(&nbsp)" as well but it seems all spaces are removed and the &nbsp is actually printed as part of the checkbox title

foreach $bit (@the_list) { $the_labels{$bit} = $bit . "&nbsp&nbsplabel1 " . " description + "; }

Any help on what i might be doing wrong would be appreciated.

TIA Li

Updated for clarity. What i've got is some perl CGI scripts, one of these scripts functions is to display a vertical list of checkboxes that has a corresponding description next to it.
Now this description is actually derived from different places, so when i display the check_boxes, instead of the label being one complete string seperated by a single space, i actually require tabs and multiple spaces in the description.

The code i got for displaying a checkbox_group came from Perl monks CGI help pages. http://www.perlmonks.com/index.pl?node=perlman%3Alib%3ACGI%3A2

From this code it shows that a checkbox_group label is a pointer to an associative array relating the checkbox values to the user-visible labels.

Replies are listed 'Best First'.
Re: Formatting labels of checkbox groups
by chromatic (Archbishop) on Aug 16, 2004 at 04:09 UTC

    I'm not sure exactly what you want, but HTML entities need a trailing semicolon. Use   instead.

      thanks for the quick reply chromatic,

      sorry i hadnt made myself clearer. What i've got is some perl CGI scripts, one of these scripts functions is to display a vertical list of checkboxes that has a corresponding description next to it.
      Now this description is actually derived from different places, so when i display the check_boxes, instead of the label being one complete string seperated by a single space, i actually require tabs and multiple spaces in the description.

      The code i got for displaying a checkbox_group came from Perl monks CGI help pages. http://www.perlmonks.com/index.pl?node=perlman%3Alib%3ACGI%3A2

      From this code it shows that a checkbox_group label is a pointer to an associative array relating the checkbox values to the user-visible labels.

      i did try placing a semi colon into my code but now it prints the textboxes as expected as well as the   between each description item

        That's because checkbox HTML-escapes its label parameters. You can call checkbox with -label => '' and then put in your string with  's by hand after the checkbox.
Re: Formatting labels of checkbox groups
by Zed_Lopez (Chaplain) on Aug 16, 2004 at 05:02 UTC
    From an old version of the docs, and still applicable in CGI.pm 3.04:
    This function actually returns an array of button elements. You can capture the array and do interesting things with it, such as incorporating it into your own tables or lists. The -nolabels option is also useful in this regard:
    @h=$query->checkbox_group(-name=>'choice',-value=>['fee','fie','foe'], + -nolabels=>1); create_nice_table(@h);
    Or generate them one at a time in a loop with
    CGI::checkbox(-name => 'the_group', -value => $value, -label =>'')
    , giving them all the same name, and CGI.pm can process it just like it was made with checkbox_group.
      Hey Zed,

      I've tried to generate the checkboxes one at a time like in your second example.

      CGI::checkbox(-name => 'the_group', -value => $value, -label =>'')

      Now what i require is something similar to...

      $some_spaces = " " #here are 4 spaces. $my_label = $title . $some_spaces . $description . $somespaces . $more +text # the variables above just represent some basic information CGI::checkbox(-name => 'the_group', -value => $value, -label =>$my_lab +el)
      now what i'd expect from the web page is a checkbox with a label that has each part split by 4 spaces.
      Unfortunately the html is being smart and removing unnecessary white space, so what i end up with is each variable only being seperated by a single space, ideally what im looking for is a way to get around this.
      any more ideas would be appreciated

      thanks

        Sorry, I thought the crux of the matter was doing complex, dynamic labelling that was inconvenient with checkbox_group.

        Like the first respondent said, you could use ' ' x 4 instead of 4 spaces. If what you really want is columns, use HTML tables or CSS.

        Or use -label => '' and put in your own label after the checkbox by hand with CGI::pre("$title    $description    $moretext")

Re: Formatting labels of checkbox groups (bug)
by tye (Sage) on Aug 16, 2004 at 06:41 UTC

    I consider it a bug in CGI.pm that labels have their HTML escaped as entities. So I patched the copies used by PerlMonks to fix this bug.

    - tye        

      thanks tye,
      was starting to go bonkers at the number of times i've tried to change my code to get this to work ...