CGI with html
cpghost
cpghost at cordula.ws
Thu Sep 6 19:22:22 PDT 2007
On Fri, 07 Sep 2007 01:33:15 +0200
Olivier Regnier <oregnier at oregnier.net> wrote:
> # MODULES
> use CGI qw(:standard);
>
> # HTML PAGE
> print header,
> start_html (
> -title => '403, Interdit',
> -style => {-code => $style },
> ),
> end_html;
[snip]
> # ------------------------------------
> and here is the result in html:
> # ------------------------------------
>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
> xml:lang="en-US"> <head>
[snip]
> I would like to have this dtd:
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> and this meta code, <meta http-equiv="Content-Type"
> content="text/html; charset=iso-8859-1" /> is not at the good place.
> Logically he is before CSS style.
>
> Can you help me please ? Sorry for my english.
Uhhh... it's a long time since I've used CGI.pm. But if I remember
correctly, the DTD was hard-coded in CGI.pm itself, and output by
start_html(); but you could override it with a value of your own.
From /usr/local/lib/perl5/5.8.8/CGI.pm:
---------------------------------------
use constant XHTML_DTD => ['-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'];
...
(And further down)
...
# >>>>> Here are some globals that you might want to adjust <<<<<<
sub initialize_globals {
# Set this to 1 to enable copious autoloader debugging messages
$AUTOLOAD_DEBUG = 0;
# Set this to 1 to generate XTML-compatible output
$XHTML = 1;
# Change this to the preferred DTD to print in start_html()
# or use default_dtd('text of DTD to use');
$DEFAULT_DTD = [ '-//W3C//DTD HTML 4.01 Transitional//EN',
'http://www.w3.org/TR/html4/loose.dtd' ] ;
...
(scroll down again)
...
#### Method: start_html
# Canned HTML header
#
# Parameters:
# $title -> (optional) The title for this HTML document (-title)
# $author -> (optional) e-mail address of the author (-author)
# $base -> (optional) if set to true, will enter the BASE address of
this document # for resolving relative references (-base)
# $xbase -> (optional) alternative base at some remote location (-xbase)
# $target -> (optional) target window to load all links into (-target)
# $script -> (option) Javascript code (-script)
# $no_script -> (option) Javascript <noscript> tag (-noscript)
# $meta -> (optional) Meta information tags
# $head -> (optional) any other elements you'd like to incorporate into
the <head> tag # (a scalar or array ref)
# $style -> (optional) reference to an external style sheet
# @other -> (optional) any other named parameters you'd like to
incorporate into # the <body> tag.
####
'start_html' => <<'END_OF_FUNC',
sub start_html {
my($self, at p) = &self_or_default(@_);
my($title,$author,$base,$xbase,$script,$noscript,
$target,$meta,$head,$style,$dtd,$lang,$encoding,$declare_xml, at other)
= rearrange([TITLE,AUTHOR,BASE,XBASE,SCRIPT,NOSCRIPT,TARGET,
META,HEAD,STYLE,DTD,LANG,ENCODING,DECLARE_XML], at p);
$self->element_id(0);
$self->element_tab(0);
$encoding = 'iso-8859-1' unless defined $encoding;
# Need to sort out the DTD before it's okay to call escapeHTML().
my(@result,$xml_dtd);
if ($dtd) {
if (defined(ref($dtd)) and (ref($dtd) eq 'ARRAY')) {
$dtd = $DEFAULT_DTD unless $dtd->[0] =~ m|^-//|;
} else {
$dtd = $DEFAULT_DTD unless $dtd =~ m|^-//|;
}
} else {
$dtd = $XHTML ? XHTML_DTD : $DEFAULT_DTD;
}
(etc. etc. etc...)
So you may want to change stuff in initialize_globals or use
default_dtd("your own DTD") or change the constant XHTML_DTD
itself, if nothing else works.
But are you sure that CGI.pm will generate *strict* XHTML
for you? They're setting the DTD to transitional for some
reason, I think.
Regarding the relative order in the header, try playing
with the parameters of start_html.
Good luck!
> Thank you in advance.
>
> Olivier
Regards,
-cpghost.
--
Cordula's Web. http://www.cordula.ws/
More information about the freebsd-questions
mailing list