Re: first steps with mod_perl

2007-10-09 Thread Marek


Hi Gunnar,

if I understand well, it is extremely difficult to make CGI.pm produce
valid html

My problem are the many p / tags in the form - and the checked
instead of checked=checked in the input-tags. But probably I am not
yet understanding CGI.pm?

Probably it is really easier, to print directly avoiding CGI.pm, as
Gunnar suggested?


Greetings to all


marek


My example-script looks now like follows:

#! /usr/bin/perl -wT

use strict;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use CGI qw/:standard/;
use Socket;

my VARS

my $email =  [EMAIL PROTECTED];
my $url   =  http://example.org;;
my %colours   = (
  red = #ff,
  green = #00ff00,
  blue = #ff,
  black = #00,
  white = #ff
  );

my $hostname  = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}), AF_INET);

my $ua = $ENV{HTTP_USER_AGENT};
my $ref = $ENV{HTTP_REFERER};

END my VARS#

print header;


print start_html(-dtd=[ '-//W3C//DTD XHTML 1.0 Strict//EN',

'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd' ],
 -title='Hello World, Address, Colours',
 -head=[Link({-rel='stylesheet',
   -href='../styles/style.css',
   -type='text/css',
   -media='screen'})
   ]
 ),
h1('Hello World!'),
p('And this is a comment to my first Hello World Script!'),

p(My email is $email and my webpage is,
a({-href=$url},http://example.org;));

print p;

foreach my $colour (keys %colours) {
print qq(span style=class:time1; color:$colours{$colour}
$colour/spanbr /\n);
}
print /p;

print p(Welcome, dear Visitor from em$hostname/em !);

print p;

print Your Browser is: $uabr /br /;
if ($ua =~ /MSIE/){
print your browser is Internet Explorer!br /br /;
} elsif ($ua =~ /Netscape/i){
print your browser is Netscape!br /br /;
} elsif ($ua =~ /Safari/i){
print your browser is Safari! Most likely your Operating System
is Macintosh! Isn't it?br /br /;
} elsif ($ua =~ /Opera/i){
print your browser is Opera!br /br /;
} elsif ($ua =~ /Mozilla/i){
print your browser is probably Mozilla!br /br /;
} elsif ($ua =~ /Lynx/i){
print your browser is probably Lynx!br /br /;
} else {
print I give up! Don't know which Browser you are using!br /
br /;
}
print br /br /your Referring Page was: $ref;
print /p;

print start_form,
p,(What's your name? ,textfield('name')),
p,(What's the combination? ,
checkbox_group(-name='words',
  -values=['eenie','meenie,-checked=checked','minie','moe'],
  -defaults=['eenie','minie'])),
p(What's your favorite color? ,
popup_menu(-name='color',
   -values=['red','green','blue','chartreuse']),
submit),
end_form,
print hr({-class='guest3'});

if (param()) {
my $name  = param('name');
my $keywords  = join ', ',param('words');
my $color = param('color');
print p,(Your name is ,em(escapeHTML($name))),
p,(The keywords are: ,em(escapeHTML($keywords))),
p,(Your favorite color is ,em(escapeHTML($color))),
hr({-class='guest3'});
}

print hr({-class='guest3'}),
end_html;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: first steps with mod_perl

2007-10-09 Thread David Dorward

On 9 Oct 2007, at 04:04, Marek wrote:

if I understand well, it is extremely difficult to make CGI.pm produce
valid html

My problem are the many p / tags in the form - and the checked
instead of checked=checked in the input-tags. But probably I am not
yet understanding CGI.pm?


It has been a long while since I tried generating HTML with CGI.pm  
(these days I lean very strongly towards Template-Toolkit), but I'd  
be surprised if it produced p / since its either non-Appendix C  
conformant, nonsensical XHTML (a content-less paragraph) or its, in  
HTML, Start of paragraph followed by a greater than sign and using  
features marked as badly supported - avoid.


checked rather than checked=checked is fine in HTML  
(checked=checked is another of the avoid this, its badly  
supported features).


According to the CGI.pm documentation, it defaults to XHTML (so it  
should be outputting checked=checked) unless you use -dtd to  
specify an HTML 2.0 or 3.2 DTD. (Why not HTML 4.x I've no idea). You  
can also use the -no_xhtml pragma to turn off XHTML generation.


Turning off XHTML generation is generally a good thing: http:// 
www.webdevout.net/articles/beware-of-xhtml


... but I'll stick to Template-Toolkit

--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/