Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Sep 2007 04:25:41 +0200
From:      cpghost <cpghost@cordula.ws>
To:        Olivier Regnier <oregnier@oregnier.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: CGI with html
Message-ID:  <20070907042541.354817af@epia-2.farid-hajji.net>
In-Reply-To: <46E08E3B.7050407@oregnier.net>
References:  <46E08E3B.7050407@oregnier.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 07 Sep 2007 01:33:15 +0200
Olivier Regnier <oregnier@oregnier.net> wrote:

> # MODULES
> use CGI qw(:standard);
>=20
> # HTML PAGE
> print header,
>       start_html (
>          -title   =3D> '403, Interdit',
>          -style   =3D> {-code =3D> $style },
>       ),
>       end_html;

[snip]

> # ------------------------------------
> and here is the result in html:
> # ------------------------------------
>=20
> <!DOCTYPE html
> 	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> 	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
> <html xmlns=3D"http://www.w3.org/1999/xhtml" lang=3D"en-US"
> xml:lang=3D"en-US"> <head>

[snip]

> I would like to have this dtd:
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"=20
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">;
> and this meta code, <meta http-equiv=3D"Content-Type"
> content=3D"text/html; charset=3Diso-8859-1" /> is not at the good place.
> Logically he is before CSS style.
>=20
> 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.

=46rom /usr/local/lib/perl5/5.8.8/CGI.pm:
---------------------------------------

use constant XHTML_DTD =3D> ['-//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 =3D 0;

    # Set this to 1 to generate XTML-compatible output
    $XHTML =3D 1;

    # Change this to the preferred DTD to print in start_html()
    # or use default_dtd('text of DTD to use');
    $DEFAULT_DTD =3D [ '-//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)=20
# $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' =3D> <<'END_OF_FUNC',
sub start_html {
    my($self,@p) =3D &self_or_default(@_);
    my($title,$author,$base,$xbase,$script,$noscript,
        $target,$meta,$head,$style,$dtd,$lang,$encoding,$declare_xml,@other)
=3D rearrange([TITLE,AUTHOR,BASE,XBASE,SCRIPT,NOSCRIPT,TARGET,
                   META,HEAD,STYLE,DTD,LANG,ENCODING,DECLARE_XML],@p);

    $self->element_id(0);
    $self->element_tab(0);

    $encoding =3D '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 =3D $DEFAULT_DTD unless $dtd->[0] =3D~ m|^-//|;
        } else {
            $dtd =3D $DEFAULT_DTD unless $dtd =3D~ m|^-//|;
        }
    } else {
        $dtd =3D $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.
>=20
> Olivier

Regards,
-cpghost.

--=20
Cordula's Web. http://www.cordula.ws/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070907042541.354817af>