CGI
view release on metacpan or search on metacpan
lib/CGI/HTML/Functions.pod view on Meta::CPAN
Import all methods that generate HTML 3.0 elements (such as
<table>, <super> and <sub>).
=item B<:html4>
Import all methods that generate HTML 4 elements (such as
<abbrev>, <acronym> and <thead>).
=item B<:netscape>
Import the <blink>, <fontsize> and <center> tags.
=item B<:html>
Import all HTML-generating shortcuts (i.e. 'html2', 'html3', 'html4' and 'netscape')
=item B<:standard>
Import "standard" features, 'html2', 'html3', 'html4', 'ssl', 'form' and 'cgi'.
=back
If you import any of the state-maintaining CGI or form-generating methods,
a default CGI object will be created and initialized automatically the first
time you use any of the methods that require one to be present. This includes
B<param()>, B<textfield()>, B<submit()> and the like. (If you need direct access
to the CGI object, you can find it in the global variable B<$CGI::Q>).
=head2 Pragmas
Additional HTML generation related pragms:
=over 4
=item -nosticky
By default the CGI module implements a state-preserving behavior called
"sticky" fields. The way this works is that if you are regenerating a form,
the methods that generate the form field values will interrogate param()
to see if similarly-named parameters are present in the query string. If
they find a like-named parameter, they will use it to set their default values.
Sometimes this isn't what you want. The B<-nosticky> pragma prevents this
behavior. You can also selectively change the sticky behavior in each element
that you generate.
=item -tabindex
Automatically add tab index attributes to each form field. With this option
turned off, you can still add tab indexes manually by passing a -tabindex
option to each field-generating method.
=item -no_xhtml
By default, CGI.pm versions 2.69 and higher emit XHTML
(http://www.w3.org/TR/xhtml1/). The -no_xhtml pragma disables this feature.
Thanks to Michalis Kabrianis <kabrianis@hellug.gr> for this feature.
If start_html()'s -dtd parameter specifies an HTML 2.0, 3.2, 4.0 or 4.01 DTD,
XHTML will automatically be disabled without needing to use this pragma.
=back
=head2 Special forms for importing HTML-tag functions
Many of the methods generate HTML tags. As described below, tag functions
automatically generate both the opening and closing tags. For example:
print h1('Level 1 Header');
produces
<h1>Level 1 Header</h1>
There will be some times when you want to produce the start and end tags
yourself. In this case, you can use the form start_I<tag_name> and
end_I<tag_name>, as in:
print start_h1,'Level 1 Header',end_h1;
=head2 Creating the HTML document header
print start_html(
-title => 'Secrets of the Pyramids',
-author => 'fred@capricorn.org',
-base => 'true',
-target => '_blank',
-meta => {'keywords'=>'pharaoh secret mummy',
'copyright' => 'copyright 1996 King Tut'},
-style => {'src'=>'/styles/style1.css'},
-BGCOLOR => 'blue'
);
The start_html() routine creates the top of the page, along with a lot of
optional information that controls the page's appearance and behavior.
This method returns a canned HTML header and the opening <body> tag. All
parameters are optional. In the named parameter form, recognized parameters
are -title, -author, -base, -xbase, -dtd, -lang and -target (see below for the
explanation). Any additional parameters you provide, such as the unofficial
BGCOLOR attribute, are added to the <body> tag. Additional parameters must be
proceeded by a hyphen.
The argument B<-xbase> allows you to provide an HREF for the <base> tag different
from the current location, as in
-xbase => "http://home.mcom.com/"
All relative links will be interpreted relative to this tag.
The argument B<-target> allows you to provide a default target frame for all the
links and fill-out forms on the page. B<This is a non-standard HTTP feature>
B<which only works with some browsers!>
-target => "answer_window"
All relative links will be interpreted relative to this tag. You add arbitrary
meta information to the header with the B<-meta> argument. This argument expects
a reference to a hash containing name/value pairs of meta information. These will
be turned into a series of header <meta> tags that look something like this:
lib/CGI/HTML/Functions.pod view on Meta::CPAN
print isindex(-action=>$action);
-or-
print isindex($action);
Prints out an <isindex> tag. Not very exciting. The parameter
-action specifies the URL of the script to process the query. The
default is to process the query with the current script.
=head2 Starting and ending a form
print start_form(-method=>$method,
-action=>$action,
-enctype=>$encoding);
<... various form stuff ...>
print end_form;
-or-
print start_form($method,$action,$encoding);
<... various form stuff ...>
print end_form;
start_form() will return a <form> tag with the optional method,
action and form encoding that you specify. The defaults are:
method: POST
action: this script
enctype: application/x-www-form-urlencoded for non-XHTML
multipart/form-data for XHTML, see multipart/form-data below.
end_form() returns the closing </form> tag.
start_form()'s enctype argument tells the browser how to package the various
fields of the form before sending the form to the server. Two
values are possible:
=over 4
=item B<application/x-www-form-urlencoded>
This is the older type of encoding. It is compatible with many CGI scripts and is
suitable for short fields containing text data. For your
convenience, CGI.pm stores the name of this encoding
type in B<&CGI::URL_ENCODED>.
=item B<multipart/form-data>
This is the newer type of encoding.
It is suitable for forms that contain very large fields or that
are intended for transferring binary data. Most importantly,
it enables the "file upload" feature. For
your convenience, CGI.pm stores the name of this encoding type
in B<&CGI::MULTIPART>
Forms that use this type of encoding are not easily interpreted
by CGI scripts unless they use CGI.pm or another library designed
to handle them.
If XHTML is activated (the default), then forms will be automatically
created using this type of encoding.
=back
The start_form() method uses the older form of encoding by
default unless XHTML is requested. If you want to use the
newer form of encoding by default, you can call
B<start_multipart_form()> instead of B<start_form()>. The
method B<end_multipart_form()> is an alias to B<end_form()>.
JAVASCRIPTING: The B<-name> and B<-onSubmit> parameters are provided
for use with JavaScript. The -name parameter gives the
form a name so that it can be identified and manipulated by
JavaScript functions. -onSubmit should point to a JavaScript
function that will be executed just before the form is submitted to your
server. You can use this opportunity to check the contents of the form
for consistency and completeness. If you find something wrong, you
can put up an alert box or maybe fix things up yourself. You can
abort the submission by returning false from this function.
Usually the bulk of JavaScript functions are defined in a <script>
block in the HTML header and -onSubmit points to one of these function
call. See start_html() for details.
=head2 Form elements
After starting a form, you will typically create one or more
textfields, popup menus, radio groups and other form elements. Each
of these elements takes a standard set of named arguments. Some
elements also have optional arguments. The standard arguments are as
follows:
=over 4
=item B<-name>
The name of the field. After submission this name can be used to
retrieve the field's value using the param() method.
=item B<-value>, B<-values>
The initial value of the field which will be returned to the script
after form submission. Some form elements, such as text fields, take
a single scalar -value argument. Others, such as popup menus, take a
reference to an array of values. The two arguments are synonyms.
=item B<-tabindex>
A numeric value that sets the order in which the form element receives
focus when the user presses the tab key. Elements with lower values
receive focus first.
=item B<-id>
A string identifier that can be used to identify this element to
JavaScript and DHTML.
=item B<-override>
A boolean, which, if true, forces the element to take on the value
specified by B<-value>, overriding the sticky behavior described
earlier for the B<-nosticky> pragma.
=item B<-onChange>, B<-onFocus>, B<-onBlur>, B<-onMouseOver>, B<-onMouseOut>, B<-onSelect>
These are used to assign JavaScript event handlers. See the
( run in 0.909 second using v1.01-cache-2.11-cpan-0b5f733616e )