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

I am trying to format a checkbox_group() label w/CGI.pm. I create the %labels hash where the values have some HTML tags in it. However the checkbox_group method changes the HTML tags to > < and the HTML tag is printed instead of formatting the text. Is there anyway to have HTML tags apply to format the label values?
%lables = ( 'key1 => '<b val1 /b>', 'key2 => '<b val2 /b> );
this is changed to &lt;b val1 /b&gt; appears in browser as <b val1 /b> next to the check box.

Replies are listed 'Best First'.
Re: formatting a checkbox label w/CGI.pm
by PodMaster (Abbot) on Jul 23, 2002 at 21:24 UTC
    I suggest you revisit the CGI documentation, and look for the word autoEscape

    Just turn autoEscape off and then it will work.

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: formatting a checkbox label w/CGI.pm
by hacker (Priest) on Jul 24, 2002 at 01:48 UTC
    I don't know what this is:
    '<b val1 /b>'
    ..but it's definately not HTML. In any case, look into CGI.pm. I notice you have a few typos in your code as well:
    %lables = ( 'key1 => '<b val1 /b>', ^ no closing quote 'key2 => '<b val2 /b> ); ^ missing ' ^ another one missing
    You also indicate you're using the %labels hash, but you called it %lables in your example. As long as you are consistant with your misspelling of hash names, perl won't care, but if this was a mistake, you'll definately not get the results you want.
      Thanks for your response (podmaster and hacker). Sorry, I wasn't very careful proof-reading my code examples. I meant to use  <b> val1 </b> for the HTML example (and I constantly mispell the word labels, use strict; preserves my sanity when consulting the interpreter.)

      I tried to use $query->autoEscape(0) to instruct the CGI.pm module not to change the HTML codes in the labels hash, but it did not work. After a bit of investigating I discovered the web server I'm using, has CGI.pm v3.01 and apparently the autoescape function has been disabled in this version. I downloaded a copy of CGI.pm v2.81 from CPAN and modified the @INC array (at the beginning of my script) to pick up the older version. Now I'm getting the results I expect.

      thanks again for your help