Home > Archive > PERL CGI Beginners > March 2005 > Formatting Labels with CGI.pm
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Formatting Labels with CGI.pm
|
|
| Bill Stephenson 2005-03-25, 3:55 pm |
| I'm trying to format the text used in my labels for a radio box group
created with CGI.pm... Among other things, I've tried:
######### code
my $payPal_label= b(Pay Online with PayPal)," (Use this for instant
access)";
my $check_label=qq~ <b>Send a Check in the Mail.</b> (If you're having
a difficult time making a payment with PayPal use this option
instead.)~;
my %payment_labels = ('PayPal'=>"$payPal_label",
'Check' =>"$check_label");
my $payment_type=$Q->radio_group(-name=>'payment_type',
-values=>['PayPal', 'Check'],
-default=>'PayPal',
-linebreak=>1,
-labels=>\%payment_labels);
######### end code
The "Bold" text doesn't work on either of the labels. As I said, I've
tried to do this in a variety of ways, but I keep getting an error or
the browser displays the "<b>" tags because CGI.pm converts it to this,
"<b>".
I know there must be a way to do this and any help to get me over this
hump would be much appreciated.
Kindest Regards,
--
Bill Stephenson
| |
| Charles K. Clarkson 2005-03-25, 3:55 pm |
| Bill Stephenson <mailto:bills@secureshopper.com> wrote:
: I'm trying to format the text used in my labels for a radio box group
: created with CGI.pm... Among other things, I've tried:
:
I'm guessing that you have something like this somewhere.
use CGI qw/:standard/;
my $Q = CGI->new();
It is not good idea to mix the function and object oriented calls
to CGI.pm.
: my $payPal_label= b(Pay Online with PayPal)," (Use this for instant
: access)";
You should consider enabling strict and warnings. There are a few
problems up there.
my $payPal_label = $Q->b( 'Pay Online with PayPal.' ) .
' (Use this for instant access)';
: my $check_label=qq~ <b>Send a Check in the Mail.</b> (If you're
: having a difficult time making a payment with PayPal use this option
: instead.)~;
:
: my %payment_labels = ('PayPal'=>"$payPal_label",
: 'Check' =>"$check_label");
Do not quote variables. ( Perlfaq4 ).
my %payment_labels = (
PayPal => $payPal_label,
Check => $check_label
);
: my $payment_type=$Q->radio_group(-name=>'payment_type',
: -values=>['PayPal',
'Check'],
: -default=>'PayPal',
: -linebreak=>1,
:
-labels=>\%payment_labels);
:
: ######### end code
:
: The "Bold" text doesn't work on either of the labels. As I said, I've
: tried to do this in a variety of ways, but I keep getting an error or
: the browser displays the "<b>" tags because CGI.pm converts it to
: this, "<b>".
In the CGI.pm docs, read the section on AUTOESCAPING HTML.
$Q->autoEscape(0);
my @payment_type = $Q->radio_group(
-name => 'payment_type',
-values => ['PayPal', 'Check'],
-default => 'PayPal',
-linebreak => 1,
-labels => \%payment_labels
);
$Q->autoEscape(1);
Or (better):
my @payment_type;
{
my $flag = $Q->autoEscape(0);
@payment_type = $Q->radio_group(
-name => 'payment_type',
-values => ['PayPal', 'Check'],
-default => 'PayPal',
-linebreak => 1,
-labels => \%payment_labels
);
$Q->autoEscape( $flag );
}
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| Lawrence Statton 2005-03-25, 3:55 pm |
| > I'm trying to format the text used in my labels for a radio box group
> created with CGI.pm... Among other things, I've tried:
>
> I know there must be a way to do this and any help to get me over this
> hump would be much appreciated.
>
The simplest solution is to temporarily turn off autoEscape
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = new CGI;
$q->autoEscape(0);
my %options = ( PayPal => '<b>Pay Online With Winning PayPal</b>',
Check => '<b>Pay With Sucky Old Check</b>' );
print $q->radio_group( -name => 'payment_type',
-values => [ keys %options ],
-default => 'PayPal',
-linebreak => 1,
-labels => \%options ) ;
$q->autoEscape(1);
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
| |
| Bill Stephenson 2005-03-26, 8:55 am |
| On Mar 25, 2005, at 11:55 AM, Lawrence Statton wrote:
> The simplest solution is to temporarily turn off autoEscape
>
Indeed it is. I'll try and remember this, again.
On Mar 25, 2005, at 11:55 AM, Charles K. Clarkson wrote:
> I'm guessing that you have something like this somewhere.
>
> use CGI qw/:standard/;
> my $Q = CGI->new();
>
No. I have this...
use CGI;
my $Q = new CGI;
But I would have tried it ;) I don't keep much html in my perl code
and hardly ever use CGI.pm's built-in html formatting. I want these
radio buttons to maintain state and got to dinking with the "-labels",
which then lead me to try and format the text... in almost every
conceivable way but the right one.
A big thanks to both Lawrence and Charles.
--
Bill Stephenson
|
|
|
|
|