CGI::HT...nctions(3)
๐ NAME ๐
okay bestie, this is the CGI::HTML::Functions(3) manual page โ literally the Documentation for CGI.pm Legacy HTML Functionality. User Contributed Perl Documentation vibe, no cap. ๐
๐ธ SYNOPSIS ๐ธ
๐จ okay so literally nothing here โ please do not use this functionality, it is considered to be legacy and essentially deprecated. This documentation exists solely to aid in maintenance and migration of legacy code using this functionality and you are strongly encouraged to migrate away from it. If you are working on new code you should be using a template engine. For more information see CGI::Alternatives.
If you really want to continue using the HTML generation functionality of CGI.pm then you should take a look at HTML::Tiny instead, which may give you a migration path away from CGI.pm's html generation functions; i strongly encourage you to move towards template driven page generation for anything involving markup as it will make porting your app to other frameworks much easier in the long run. No cap, template-driven is the main character here. โจ
๐ DESCRIPTION ๐
The documentation here should be considered an addendum to the sections in the CGI documentation โ the sections here are named the same as those within the CGI perldoc. iykyk. ๐ฆ
๐ฆ Calling CGI.pm routines ๐ฆ
HTML tag functions have both attributes (the attribute="value" pairs within the tag itself) and contents (the part between the opening and closing pairs). To distinguish between attributes and contents, CGI.pm uses the convention of passing HTML attributes as a hash reference as the first argument, and the contents, if any, as any subsequent arguments. It works out like this:
Code Generated HTML
---- --------------
h1() <h1 />
h1('some','contents'); <h1>some contents</h1>
h1({-align=>left}); <h1 align="LEFT">
h1({-align=>left},'contents'); <h1 align="LEFT">contents</h1>
Many newcomers to CGI.pm are lowkey puzzled by the difference between the calling conventions for the HTML shortcuts, which require curly braces around the HTML tag attributes, and the calling conventions for other routines, which manage to generate attributes without the curly brackets. Don't be confused. As a convenience the curly braces are optional in all but the HTML shortcuts. If you like, you can use curly braces when calling any routine that takes named arguments. For example:
print $q->header( { -type => 'image/gif', -expires => '+3d' } );
ngl, if you use warnings, you will be warned that some CGI.pm argument names conflict with built-in perl functions. The most frequent of these is the -values argument, used to create multi-valued menus, radio button clusters and the like. To get around this warning, you have several choices:
- Use another name for the argument, if one is available. For example,
-valueis an alias for-values. - Change the capitalization, e.g.
-Values. - Put quotes around the argument name, e.g.
'-values'.
๐ Function-oriented interface HTML exports ๐
Here is a list of the HTML related function sets you can import, bestie:
:formโ Import all fill-out form generating methods, such astextfield().:html2โ Import all methods that generate HTML 2.0 standard elements.:html3โ Import all methods that generate HTML 3.0 elements (such as<table>,<super>and<sub>).:html4โ Import all methods that generate HTML 4 elements (such as<abbrev>,<acronym>and<thead>).:netscapeโ Import the<blink>,<fontsize>and<center>tags.:htmlโ Import all HTML-generating shortcuts (i.e.'html2','html3','html4'and'netscape').:standardโ Import"standard"features,'html2','html3','html4','ssl','form'and'cgi'.
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 param(), textfield(), submit() and the like. (If you need direct access to the CGI object, you can find it in the global variable $CGI::Q). fr fr. ๐ซถ
โจ Pragmas โจ
Additional HTML generation related pragmas, incoming:
-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 interrogateparam()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 (lowkey annoying). The-nostickypragma prevents this behavior. You can also selectively change the sticky behavior in each element that you generate.-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-tabindexoption to each field-generating method. slay.-no_xhtmlโ By default, CGI.pm versions2.69and higher emit XHTML (http://www.w3.org/TR/xhtml1/). The-no_xhtmlpragma disables this feature. Thanks to Michalis Kabrianis<kabrianis@hellug.gr>for this feature. Ifstart_html()'s-dtdparameter specifies an HTML 2.0, 3.2, 4.0 or 4.01 DTD, XHTML will automatically be disabled without needing to use this pragma.
๐ 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_tag_name and end_tag_name, as in:
print start_h1,'Level 1 Header',end_h1;
๐ Creating the HTML document header ๐
okay so here's the iconic start_html() moment:
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 preceded by a hyphen. periodt. ๐
The argument -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 -target allows you to provide a default target frame for all the links and fill-out forms on the page. This is a non-standard HTTP feature 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 -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:
<meta name="keywords" content="pharaoh secret mummy">
<meta name="description" content="copyright 1996 King Tut">
To create an HTTP-EQUIV type of <meta> tag, use -head, described below.
The -style argument is used to incorporate cascading stylesheets into your code. See the section on CASCADING STYLESHEETS for more information.
The -lang argument is used to incorporate a language attribute into the <html> tag. For example:
print $q->start_html( -lang => 'fr-CA' );
The default if not specified is "en-US" for US English, unless the -dtd parameter specifies an HTML 2.0 or 3.2 DTD, in which case the lang attribute is left off. You can force the lang attribute to left off in other cases by passing an empty string (-lang=>'').
The -encoding argument can be used to specify the character set for XHTML. It defaults to iso-8859-1 if not specified.
The -dtd argument can be used to specify a public DTD identifier string. For example:
-dtd => '-//W3C//DTD HTML 4.01 Transitional//EN')
Alternatively, it can take public and system DTD identifiers as an array:
-dtd => [
'-//W3C//DTD HTML 4.01 Transitional//EN',
'http://www.w3.org/TR/html4/loose.dtd'
]
For the public DTD identifier to be considered, it must be valid. Otherwise it will be replaced by the default DTD. If the public DTD contains 'XHTML', CGI.pm will emit XML.
The -declare_xml argument, when used in conjunction with XHTML, will put a <?xml> declaration at the top of the HTML header. The sole purpose of this declaration is to declare the character set encoding. In the absence of -declare_xml, the output HTML will contain a <meta> tag that specifies the encoding, allowing the HTML to pass most validators. The default for -declare_xml is false.
You can place other arbitrary HTML elements to the <head> section with the -head tag. For example, to place a <link> element in the head section, use this:
print start_html(
-head => Link({
-rel => 'shortcut icon',
-href => 'favicon.ico'
})
);
To incorporate multiple HTML elements into the <head> section, just pass an array reference:
print start_html(
-head => [
Link({
-rel => 'next',
-href => 'http://www.capricorn.com/s2.html'
}),
Link({
-rel => 'previous',
-href => 'http://www.capricorn.com/s1.html'
})
]
);
And here's how to create an HTTP-EQUIV <meta> tag:
print start_html(
-head => meta({
-http_equiv => 'Content-Type',
-content => 'text/html'
})
);
JAVASCRIPTING: okay bestie, the -script, -noScript, -onLoad, -onMouseOver, -onMouseOut and -onUnload parameters are the whole JavaScript crew here โ they add JavaScript calls to your pages. โจ -script should point to a block of text containing JavaScript function definitions. That block gets placed inside a <script> block in the HTML (not HTTP) header. Why the header? So your page has a fighting chance of having all its JavaScript functions ready even if the user hits the stop button before the page finishes loading. CGI.pm tries to format the script so JavaScript-naive browsers won't choke on it โ but unfortunately some browsers still get confused by it anyway. ๐ญ
The -onLoad and -onUnload parameters point to fragments of JavaScript code to execute when the page is opened and closed by the browser, respectively. Usually these are calls to functions defined in the -script field:
$q = CGI->new;
print header;
$JSCRIPT = <<END;
// Ask a silly question
function riddle_me_this() {
var r = prompt(
"What walks on four legs in the morning, " +
"two legs in the afternoon, " +
"and three legs in the evening?"
);
response(r);
}
// Get a silly answer
function response(answer) {
if (answer == "man")
alert("Right you are!");
else
alert("Wrong! Guess again.");
}
END
print start_html(
-title => 'The Riddle of the Sphinx',
-script => $JSCRIPT
);
Use the -noScript parameter to pass some HTML text that will be displayed on browsers that don't have JavaScript (or browsers where JavaScript is turned off). ๐ซถ
The <script> tag has several attributes including "type", "charset" and "src". "src" lets you keep JavaScript code in an external file. To use these attributes, pass a HASH reference in the -script parameter containing one or more of -type, -src, or -code:
print $q->start_html(
-title => 'The Riddle of the Sphinx',
-script => {
-type => 'JAVASCRIPT',
-src => '/javascript/sphinx.js'}
);
print $q->(
-title => 'The Riddle of the Sphinx',
-script => {
-type => 'PERLSCRIPT',
-code => 'print "hello world!\n;"'
}
);
A final feature lets you incorporate multiple <script> sections into the header. Just pass the list of script sections as an array reference. This lets you specify different source files for different dialects of JavaScript. Example:
print $q->start_html(
-title => 'The Riddle of the Sphinx',
-script => [
{
-type => 'text/javascript',
-src => '/javascript/utilities10.js'
},
{
-type => 'text/javascript',
-src => '/javascript/utilities11.js'
},
{
-type => 'text/jscript',
-src => '/javascript/utilities12.js'
},
{
-type => 'text/ecmascript',
-src => '/javascript/utilities219.js'
}
]
);
The option -language is a synonym for -type, and is supported for backwards compatibility. ๐
The old-style positional parameters are as follows:
Parameters:
- The title
- The author's e-mail address (will create a
<link rev="MADE">tag if present) - A 'true' flag if you want to include a
<base>tag in the header. This helps resolve relative addresses to absolute ones when the document is moved, but it makes the document hierarchy non-portable. Use with care! โ ๏ธ
Other parameters you want to include in the <body> tag may be appended to these. This is a good place to put HTML extensions, such as colors and wallpaper patterns. ๐
๐ Ending the Html document ๐
print $q->end_html;
This ends an HTML document by printing the </body></html> tags. Iconic, honestly. ๐
๐ CREATING STANDARD HTML ELEMENTS ๐
CGI.pm defines general HTML shortcut methods for many HTML tags. HTML shortcuts are named after a single HTML element and return a fragment of HTML text. Example:
print $q->blockquote(
"Many years ago on the island of",
$q->a({href=>"http://crete.org/"},"Crete"),
"there lived a Minotaur named",
$q->strong("Fred."),
),
$q->hr;
This results in the following HTML code (extra newlines have been added for readability):
<blockquote>
Many years ago on the island of
<a href="http://crete.org/">Crete</a> there lived
a minotaur named <strong>Fred.</strong>
</blockquote>
<hr>
If you find the syntax for calling the HTML shortcuts awkward, you can import them into your namespace and dispense with the object syntax completely (see the next section for more details):
use CGI ':standard';
print blockquote(
"Many years ago on the island of",
a({href=>"http://crete.org/"},"Crete"),
"there lived a minotaur named",
strong("Fred."),
),
hr;
๐ธ Providing arguments to HTML shortcuts ๐ธ
The HTML methods will accept zero, one or multiple arguments. If you provide no arguments, you get a single tag:
print hr; # <hr>
If you provide one or more string arguments, they are concatenated together with spaces and placed between opening and closing tags:
print h1("Chapter","1"); # <h1>Chapter 1</h1>"
If the first argument is a hash reference, then the keys and values of the hash become the HTML tag's attributes:
print a({-href=>'fred.html',-target=>'_new'},
"Open a new frame");
<a href="fred.html",target="_new">Open a new frame</a>
You may dispense with the dashes in front of the attribute names if you prefer:
print img {src=>'fred.gif',align=>'LEFT'};
<img align="LEFT" src="fred.gif">
Sometimes an HTML tag attribute has no argument. For example, ordered lists can be marked as COMPACT. The syntax for this is an argument that points to an undef string:
print ol({compact=>undef},li('one'),li('two'),li('three'));
Prior to CGI.pm version 2.41, providing an empty ('') string as an attribute argument was the same as providing undef. However, this has changed in order to accommodate those who want to create tags of the form <img alt="">. The difference is shown in these two pieces of code:
CODE RESULT
img({alt=>undef}) <img alt>
img({alt=>''}) <img alt="">
๐ฆ The distributive property of HTML shortcuts ๐ฆ
One of the cool features of the HTML shortcuts is that they are distributive. If you give them an argument consisting of a reference to a list, the tag will be distributed across each element of the list. For example, here's one way to make an ordered list:
print ul(
li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy'])
);
This example will result in HTML output that looks like this:
<ul>
<li type="disc">Sneezy</li>
<li type="disc">Doc</li>
<li type="disc">Sleepy</li>
<li type="disc">Happy</li>
</ul>
This is extremely useful for creating tables. For example:
print table({-border=>undef},
caption('When Should You Eat Your Vegetables?'),
Tr({-align=>'CENTER',-valign=>'TOP'},
[
th(['Vegetable', 'Breakfast','Lunch','Dinner']),
td(['Tomatoes' , 'no', 'yes', 'yes']),
td(['Broccoli' , 'no', 'no', 'yes']),
td(['Onions' , 'yes','yes', 'yes'])
]
)
);
๐ HTML shortcuts and list interpolation ๐
Consider this bit of code:
print blockquote(em('Hi'),'mom!'));
It will ordinarily return the string that you probably expect, namely:
<blockquote><em>Hi</em> mom!</blockquote>
Note the space between the element "Hi" and the element "mom!". CGI.pm puts the extra space there using array interpolation, which is controlled by the magic $" variable. Sometimes this extra space is not what you want โ for example, when you're trying to align a series of images. In this case, you can simply change the value of $" to an empty string.
{
local($") = '';
print blockquote(em('Hi'),'mom!'));
}
I suggest you put the code in a block as shown here. Otherwise the change to $" will affect all subsequent code until you explicitly reset it. ๐จ
๐ Non-standard HTML shortcuts ๐
A few HTML tags don't follow the standard pattern for various reasons.
comment() generates an HTML comment (<!-- comment -->). Call it like:
print comment('here is my comment');
Because of conflicts with built-in perl functions, the following functions begin with initial caps:
SelectTrLinkDeleteAcceptSub
In addition, start_html(), end_html(), start_form(), end_form(), start_multipart_form() and all the fill-out form tags are special. See their respective sections.
๐ Autoescaping HTML ๐
By default, all HTML that is emitted by the form-generating functions is passed through a function called escapeHTML():
$escaped_string = escapeHTML("unescaped string");
Escape HTML formatting characters in a string. Internally this calls HTML::Entities (encode_entities) so really you should just use that instead โ the default list of chars that will be encoded (passed to the HTML::Entities encode_entities method) is:
& < > " \x8b \x9b '
You can control this list by setting the value of $CGI::ENCODE_ENTITIES:
# only encode < >
$CGI::ENCODE_ENTITIES = q{<>}
If you want to encode all entities then undef $CGI::ENCODE_ENTITIES:
# encode all entities
$CGI::ENCODE_ENTITIES = undef;
The automatic escaping does not apply to other shortcuts, such as h1(). You should call escapeHTML() yourself on untrusted data in order to protect your pages against nasty tricks that people may enter into guestbooks, etc.. To change the character set, use charset(). To turn autoescaping off completely, use autoEscape(0):
$charset = charset([$charset]);
Get or set the current character set.
$flag = autoEscape([$flag]);
Get or set the value of the autoescape flag. ๐
๐ CREATING FILL-OUT FORMS: ๐
General note, bestie โ okay so all these form-creating methods? They just return strings to you. That's it. The string contains the tag or tags that'll make the form element you asked for. You're the one responsible for actually printing them out. It's set up this way on purpose so you can wrap formatting tags around your form elements, which is lowkey iconic of it. ๐
Another note โ the default values you specify for forms are only used the first time the script is invoked (i.e. when there's no query string). On subsequent invocations (when there is a query string), the former values get used even if they're blank. Yes, even then. ๐ญ
So if you wanna change the value of a field from its previous value, you've got two choices, no cap:
- call the
param()method to set it. - use the
-override(alias-force) parameter โ a new feature in version 2.15. This forces the default value to be used, regardless of the previous value:
print textfield(-name=>'field_name',
-default=>'starting value',
-override=>1,
-size=>50,
-maxlength=>80);
Yet another note โ by default the text and labels of form elements are escaped according to HTML rules. Which means you can safely use "<CLICK ME>" as the label for a button. Slay. But it also interferes with your ability to incorporate special HTML character sequences, like Á, into your fields. So if you wanna turn off automatic escaping, call the autoEscape() method with a false value immediately after creating the CGI object:
$q = CGI->new;
$q->autoEscape(0);
Heads up though: autoEscape() is exclusively used to effect the behavior of how some CGI.pm HTML generation functions handle escaping. Calling escapeHTML() explicitly will always escape the HTML. Them's the rules. โจ
A Lurking Trap! ๐จ Some of the form-element generating methods return multiple tags. In a scalar context, the tags get concatenated together with spaces โ or whatever the current value of the $" global is. In a list context, the methods return a list of elements, so you can modify them if you wish. Usually you won't notice this behavior, but beware of this little gremlin:
printf("%s\n",end_form())
end_form() produces several tags, and only the first of them will be printed, because the format only expects one value. So you're out here leaking tags and wondering why your HTML looks cursed. ๐
<p>
๐ธ Creating an isindex tag ๐ธ
print isindex(-action=>$action);
-or-
print isindex($action);
Prints out an <isindex> tag. Not very exciting, ngl. The parameter -action specifies the URL of the script to process the query. The default is to process the query with the current script. That's it, that's the whole vibe check. ๐ฆ
๐ง 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. Here are the defaults, in a cute lil list:
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. Bookend behavior, we love to see it. ๐ซถ
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:
application/x-www-form-urlencodedโ this is the older type of encoding. It's 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&CGI::URL_ENCODED.multipart/form-dataโ this is the newer type of encoding. It's 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&CGI::MULTIPART.
Bestie, real talk: forms that use multipart/form-data are not easily interpreted by CGI scripts unless they use CGI.pm or another library designed to handle them. Don't rawdog it. ๐ญ
If XHTML is activated (the default), then forms will be automatically created using multipart/form-data encoding. Iconic default behavior. โจ
The start_form() method uses the older form of encoding by default unless XHTML is requested. If you wanna use the newer form of encoding by default, just call start_multipart_form() instead of start_form(). And the method end_multipart_form() is an alias to end_form() โ they're literally the same thing, iykyk.
JAVASCRIPTING: the -name and -onSubmit parameters are provided for use with JavaScript, bestie. The -name parameter gives the form a name so 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. And you can abort the submission by returning false from this function. Main character energy, honestly. ๐
Usually the bulk of JavaScript functions are defined in a <script> block in the HTML header, and -onSubmit points to one of these function calls. See start_html() for details. ๐
๐ฆ Form elements ๐ฆ
After starting a form, you'll 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, and yes I'm listing every single one:
-nameโ the name of the field. After submission, this name can be used to retrieve the field's value using theparam()method.-value,-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-valueargument. Others, such as popup menus, take a reference to an array of values. The two arguments are synonyms.-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.-idโ a string identifier that can be used to identify this element to JavaScript and DHTML.-overrideโ a boolean, which, if true, forces the element to take on the value specified by-value, overriding the sticky behavior described earlier for the-nostickypragma.-onChange,-onFocus,-onBlur,-onMouseOver,-onMouseOut,-onSelectโ these are used to assign JavaScript event handlers. See the JavaScripting section for more details.
Other common arguments are described in the next section. And in addition to these, all attributes described in the HTML specifications are supported. So go off, honestly. ๐
๐ Creating a text field ๐
print textfield(-name=>'field_name',
-value=>'starting value',
-size=>50,
-maxlength=>80);
-or-
print textfield('field_name','starting value',50,80);
textfield() will return a text input field. Here are the parameters, numbered because apparently we're being organized today:
- The first parameter is the required name for the field (
-name). - The optional second parameter is the default starting value for the field contents (
-value, formerly known as-default). - The optional third parameter is the size of the field in characters (
-size). - The optional fourth parameter is the maximum number of characters the field will accept (
-maxlength).
As with all these methods, the field will be initialized with its previous contents from earlier invocations of the script. Sticky behavior, love that for us. ๐ When the form is processed, the value of the text field can be retrieved with:
$value = param('foo');
And if you wanna reset it from its initial value after the script has been called once, you can do so like this:
param('foo',"I'm taking over this value!");
๐ธ Creating a big text field ๐ธ
print textarea(-name=>'foo',
-default=>'starting value',
-rows=>10,
-columns=>50);
-or
print textarea('foo','starting value',10,50);
textarea() is just like textfield, except it lets you specify rows and columns for a multiline text entry box. You can provide a starting value for the field, which can be long and contain multiple lines. Big textfield rights! ๐ค๐
๐ Creating a password field ๐
print password_field(-name=>'secret',
-value=>'starting value',
-size=>50,
-maxlength=>80);
-or-
print password_field('secret','starting value',50,80);
password_field() is identical to textfield(), except its contents will be starred out on the web page. Secretive. Mysterious. We stan a private queen. ๐โจ
๐ง Creating a file upload field ๐ง
print filefield(-name=>'uploaded_file',
-default=>'starting value',
-size=>50,
-maxlength=>80);
-or-
print filefield('uploaded_file','starting value',50,80);
filefield() will return a file upload field. In order to take full advantage of this, you must use the new multipart encoding scheme for the form. You can do this either by calling start_form() with an encoding type of &CGI::MULTIPART, or by calling the new method start_multipart_form() instead of vanilla start_form(). Don't forget or it simply won't work, bestie. ๐ญ
Parameters:
- The first parameter is the required name for the field (
-name). - The optional second parameter is the starting value for the field contents to be used as the default file name (
-default).
For security reasons, browsers don't pay any attention to this field, and so the starting value will always be blank. Worse, the field loses its "sticky" behavior and forgets its previous contents. The starting value field is called for in the HTML specification, however, and possibly some browser will eventually provide support for it. ๐ So yeah. It's giving "we put it in the spec and everyone ignored it."
- The optional third parameter is the size of the field in characters (
-size). - The optional fourth parameter is the maximum number of characters the field will accept (
-maxlength).
JAVASCRIPTING: the -onChange, -onFocus, -onBlur, -onMouseOver, -onMouseOut and -onSelect parameters are recognized. See textfield() for details. ๐ฆ
๐ฅ Creating a popup menu ๐ฅ
print popup_menu('menu_name',
['eenie','meenie','minie'],
'meenie');
-or-
%labels = ('eenie'=>'your first choice',
'meenie'=>'your second choice',
'minie'=>'your third choice');
%attributes = ('eenie'=>{'class'=>'class of first choice'});
print popup_menu('menu_name',
['eenie','meenie','minie'],
'meenie',\%labels,\%attributes);
ok so that's the old-school positional way โจ and here's the named-parameter glow-up:
-or (named parameter style)-
print popup_menu(-name=>'menu_name',
-values=>['eenie','meenie','minie'],
-default=>['meenie','minie'],
-labels=>\%labels,
-attributes=>\%attributes);
popup_menu() literally makes a menu ๐
but bestie listen โ the -multiple option gets ignored if you pass it, no cap. If you actually want a menu that supports multiple selections you gotta use scrolling_list() instead. iykyk ๐ซถ
- the required first argument is the menu's name (
-name) ๐ - the required second argument (
-values) is an array reference holding the list of menu items in the menu. you can hand it an anonymous array like in the example, or a reference to a named array, like\@foo๐ - the optional third parameter (
-default) is the name of the default menu choice. if you don't specify it, the first item becomes the default, periodt. the values of the previous choice get maintained across queries. pass an array reference if you want multiple defaults selected ๐ธ - the optional fourth parameter (
-labels) is for the girlies who want different values for the user-visible label inside the popup menu vs. the value returned to your script. it's a pointer to a hash relating menu values to user-visible labels. leave it blank and the menu values get displayed by default (you can also leave a label undefined if that's your vibe) ๐ - the optional fifth parameter (
-attributes) lets you assign any of the common HTML attributes to an individual menu item. it's a pointer to a hash relating menu values to another hash, with the attribute's name as the key and the attribute's value as the value โจ
when the form gets processed, the selected value of the popup menu can be retrieved using:
$popup_menu_value = param('menu_name');
๐ Creating an option group ๐
named parameter style, bestie:
print popup_menu(-name=>'menu_name',
-values=>[qw/eenie meenie minie/,
optgroup(-name=>'optgroup_name',
-values => ['moe','catch'],
-attributes=>{'catch'=>{'class'=>'red'}})],
-labels=>{'eenie'=>'one',
'meenie'=>'two',
'minie'=>'three'},
-default=>'meenie');
and the old style:
print popup_menu('menu_name',
['eenie','meenie','minie',
optgroup('optgroup_name', ['moe', 'catch'],
{'catch'=>{'class'=>'red'}})],'meenie',
{'eenie'=>'one','meenie'=>'two','minie'=>'three'});
optgroup() creates an option group within a popup menu ๐ฆ
- the required first argument (
-name) is the label attribute of the optgroup, and it's not inserted in the parameter list of the query ๐ซ - the required second argument (
-values) is an array reference containing the list of menu items in the menu. you can pass an anonymous array like the example shows, or a reference to a named array, such as\@foo. and plot twist โ if you pass a HASH reference, the keys get used for the menu values and the values get used for the menu labels (see-labelsbelow) ๐ - the optional third parameter (
-labels) lets you pass a reference to a hash containing user-visible labels for one or more of the menu items. use this when you want the user to see one menu string but have the browser return your program a different one. if you don't specify it, the value string gets used instead ("eenie","meenie"and"minie"in this example). this is equivalent to using a hash reference for the-valuesparameter โญ - an optional fourth parameter (
-labeled) can be set to a true value and it indicates the values should be used as the label attribute for each option element within the optgroup ๐ - an optional fifth parameter (
-novals) can be set to a true value and it indicates to suppress the val attribute in each option element within the optgroup. see the discussion on optgroup at W3C (http://www.w3.org/TR/REC-html40/interact/forms.html#edef-OPTGROUP) for the details ๐ง - an optional sixth parameter (
-attributes) is provided to assign any of the common HTML attributes to an individual menu item. it's a pointer to a hash relating menu values to another hash with the attribute's name as the key and the attribute's value as the value ๐
๐ Creating a scrolling list ๐
print scrolling_list('list_name',
['eenie','meenie','minie','moe'],
['eenie','moe'],5,'true',{'moe'=>{'class'=>'red'}});
-or-
print scrolling_list('list_name',
['eenie','meenie','minie','moe'],
['eenie','moe'],5,'true',
\%labels,%attributes);
-or-
print scrolling_list(-name=>'list_name',
-values=>['eenie','meenie','minie','moe'],
-default=>['eenie','moe'],
-size=>5,
-multiple=>'true',
-labels=>\%labels,
-attributes=>\%attributes);
scrolling_list() creates a scrolling list ๐ฅ
parameters, going down the list:
- the first and second arguments are the list name (
-name) and values (-values). same as the popup menu, that second argument should be an array reference ๐ - the optional third argument (
-default) can be either a reference to a list containing the values to be selected by default, or just a single value to select. if this argument is missing or undefined, then nothing is selected when the list first appears โ nobody's the default, iconic. in the named parameter version you can use the synonym"-defaults"for this parameter ๐ซถ - the optional fourth argument is the size of the list (
-size) โจ - the optional fifth argument can be set to true to allow multiple simultaneous selections (
-multiple). otherwise only one selection is allowed at a time ๐ธ - the optional sixth argument is a pointer to a hash containing long user-visible labels for the list items (
-labels). if not provided, the values get displayed ๐ - the optional sixth parameter (
-attributes) โ yes it says "sixth" again, we don't make the rules โ is provided to assign any of the common HTML attributes to an individual menu item. it's a pointer to a hash relating menu values to another hash with the attribute's name as the key and the attribute's value as the value ๐
when this form is processed, all selected list items get returned as a list under the parameter name 'list_name'. the values of the selected items can be retrieved with:
@selected = param('list_name');
๐ Creating a group of related checkboxes ๐
print checkbox_group(-name=>'group_name',
-values=>['eenie','meenie','minie','moe'],
-default=>['eenie','moe'],
-linebreak=>'true',
-disabled => ['moe'],
-labels=>\%labels,
-attributes=>\%attributes);
print checkbox_group('group_name',
['eenie','meenie','minie','moe'],
['eenie','moe'],'true',\%labels,
{'moe'=>{'class'=>'red'}});
HTML3-COMPATIBLE BROWSERS ONLY:
print checkbox_group(-name=>'group_name',
-values=>['eenie','meenie','minie','moe'],
-rows=2,-columns=>2);
checkbox_group() creates a list of checkboxes that are all related by the same name ๐
parameters:
- the first and second arguments are the checkbox name and values, respectively (
-nameand-values). as in the popup menu, the second argument should be an array reference. these values are used for the user-readable labels printed next to the checkboxes as well as for the values passed to your script in the query string โญ - the optional third argument (
-default) can be either a reference to a list containing the values to be checked by default, or a single value to checked. if this argument is missing or undefined, then nothing is selected when the list first appears ๐ - the optional fourth argument (
-linebreak) can be set to true to place line breaks between the checkboxes so they appear as a vertical list. otherwise they get strung together on a horizontal line ๐ฆ
the optional -labels argument is a pointer to a hash relating the checkbox values to the user-visible labels that get printed next to them. if not provided, the values get used as the default โจ
the optional parameters -rows, and -columns cause checkbox_group() to return an HTML3 compatible table containing the checkbox group formatted with the specified number of rows and columns. you can provide just the -columns parameter if you want; checkbox_group will calculate the correct number of rows for you ๐
the option -disabled takes an array of checkbox values and disables them by greying them out โ heads up, this may not be supported by all browsers ๐
the optional -attributes argument is provided to assign any of the common HTML attributes to an individual menu item. it's a pointer to a hash relating menu values to another hash with the attribute's name as the key and the attribute's value as the value ๐
the optional -tabindex argument can be used to control the order in which radio buttons receive focus when the user presses the tab button. if you pass a scalar numeric value, the first element in the group receives this tab index and subsequent elements get incremented by one. if you give it a reference to an array of radio button values, then the indexes get jiggered so that the order specified in the array corresponds to the tab order. you can also pass a reference to a hash where the hash keys are the radio button values and the values are the tab indexes of each button. examples, because seeing it is believing:
-tabindex => 100 # this group starts at index 100 and counts up
-tabindex => ['moe','minie','eenie','meenie'] # tab in this order
-tabindex => {meenie=>100,moe=>101,minie=>102,eenie=>200} # tab in this order
The optional -labelattributes argument will hold attributes that get attached to the <label> element wrapping each little button. Cute, right? ๐
So when the form actually gets processed, every checked box comes back to you as a list under the parameter name 'group_name'. Wanna grab just the ones that got turned on? Do this:
@turned_on = param('group_name');
And here's the slay part: what checkbox_group() hands back is actually an array of button elements. Like, literally a list. So you can capture them and stick them in tables, lists, or honestly whatever creative chaos you're feeling:
@h = checkbox_group(-name=>'group_name',-values=>\@values);
&use_in_creative_way(@h);
Creating a standalone checkbox ๐
print checkbox(-name=>'checkbox_name',
-checked=>1,
-value=>'ON',
-label=>'CLICK ME');
-or-
print checkbox('checkbox_name','checked','ON','CLICK ME');
checkbox() makes a single, lone-wolf checkbox that isn't logically related to any of the others. Main character energy, no group chat. โจ
Parameters:
- The first parameter is the required name for the checkbox (
-name). It also doubles as the user-readable label printed right next to the checkbox โ two jobs, one icon. - The optional second parameter (
-checked) says the checkbox is turned on by default. Synonyms are-selectedand-on. - The optional third parameter (
-value) sets the value of the checkbox when it's checked. If you don't provide one, the word"on"is assumed. Default vibes. - The optional fourth parameter (
-label) is the user-readable label attached to the checkbox. Skip it and the checkbox name gets used instead.
Wanna get the value back out? Easy:
$turned_on = param('checkbox_name');
Creating a radio button group ๐ป
print radio_group(-name=>'group_name',
-values=>['eenie','meenie','minie'],
-default=>'meenie',
-linebreak=>'true',
-labels=>\%labels,
-attributes=>\%attributes);
-or-
print radio_group('group_name',['eenie','meenie','minie'],
'meenie','true',\%labels,\%attributes);
HTML3-COMPATIBLE BROWSERS ONLY:
print radio_group(-name=>'group_name',
-values=>['eenie','meenie','minie','moe'],
-rows=2,-columns=>2);
radio_group() builds a set of logically-related radio buttons โ the whole "turning one member of the group on turns the others off" situation. Only one can be the favorite at a time, periodt. ๐
Parameters:
- The first argument is the name of the group and it's required (
-name). - The second argument (
-values) is the list of values for the radio buttons. The values and the labels showing on the page are identical. Pass an array reference in the second argument โ either an anonymous array like the example up there, or by referencing a named array like\@foo. - The optional third parameter (
-default) is the name of the default button to turn on. Don't specify it and the first item becomes the default. You can even pass a nonexistent button name, like"-", to start up with no buttons selected. Iconic little loophole. - The optional fourth parameter (
-linebreak) can be set to'true'to put line breaks between the buttons, which gives you a vertical list. - The optional fifth parameter (
-labels) is a pointer to an associative array relating the radio button values to the user-visible labels used in the display. If you don't provide it, the values themselves get displayed.
All modern browsers can take advantage of the optional -rows and -columns parameters. These make radio_group() return an HTML3 compatible table containing the radio group, formatted with however many rows and columns you asked for. You can provide just -columns if that's all you've got โ radio_group will work out the correct number of rows for you. It's doing the math so you don't have to. ๐งฎโจ
If you want row and column headings in that returned table, use the -rowheaders and -colheaders parameters. Both accept a pointer to an array of headings to use. Fair warning though: the headings are purely decorative. They do not reorganize how the radio buttons are interpreted โ it's still one single named unit, no cap. ๐
The optional -tabindex argument controls the order in which radio buttons receive focus when the user hits the tab button. Pass a scalar numeric value and the first element in the group gets that tab index, with subsequent elements incrementing by one. Pass a reference to an array of radio button values and the indexes get jiggered so the order in that array corresponds to the tab order. You can also pass a reference to a hash where the hash keys are the radio button values and the values are the tab indexes of each button. Examples, bestie:
-tabindex => 100 # this group starts at index 100 and counts up
-tabindex => ['moe','minie','eenie','meenie'] # tab in this order
-tabindex => {meenie=>100,moe=>101,minie=>102,eenie=>200} # tab in this order
The optional -attributes argument lets you assign any of the common HTML attributes to an individual menu item. It's a pointer to a hash relating menu values to another hash, that inner one having the attribute's name as the key and the attribute's value as the value. Hash-ception. ๐
The optional -labelattributes argument will contain attributes attached to the <label> element that surrounds each button.
When the form gets processed, you can retrieve the selected radio button like this:
$which_radio_button = param('group_name');
And just like with checkboxes โ what radio_group() returns is actually an array of button elements. Capture them, drop them in tables, lists, or get creative:
@h = radio_group(-name=>'group_name',-values=>\@values);
&use_in_creative_way(@h);
Creating a submit button ๐
print submit(-name=>'button_name',
-value=>'value');
-or-
print submit('button_name','value');
submit() creates the query submission button. Literally every form should have one of these โ it's the moment of commitment, the "send it" of the whole operation. ๐ซถ
Parameters:
- The first argument (
-name) is optional. Give the button a name if you've got several submission buttons in your form and you need to tell them apart. - The second argument (
-value) is also optional. This gives the button a value that will get passed to your script in the query string. The name also gets used as the user-visible label. - You can use
-labelas an alias for-value. Honestly the docs admit the author always gets confused about which of-nameand-valuechanges the user-visible label on the button. Relatable. ๐ญ
Figure out which button got pressed by giving each one a different value:
$which_one = param('button_name');
Creating a reset button ๐
print reset
reset() creates the "reset" button. Heads up though: it restores the form to its value from the last time the script was called โ NOT necessarily to the defaults. Important distinction, don't sleep on it. ๐
Also note that this conflicts with the perlreset()built-in. UseCORE::reset()to get the original reset function. Name collision, classic.
Creating a default button ๐
print defaults('button_label')
defaults() creates a button that, when invoked, will cause the form to be completely reset to its defaults โ wiping out every single change the user ever made. Full factory reset, no takesies-backsies. ๐
Creating a hidden field ๐ต๏ธโโ๏ธ
print hidden(-name=>'hidden_name',
-default=>['value1','value2'...]);
-or-
print hidden('hidden_name','value1','value2'...);
hidden() produces a text field the user can't see. Sneaky but useful โ it's for passing state variable info from one invocation of the script to the next. Behind-the-scenes queen. ๐
Parameters:
- The first argument is required and specifies the name of this field (
-name). - The second argument is also required and specifies its value (
-default). In the named parameter style of calling, you can hand over a single value here, or a reference to a whole entire list.
Fetch the value of a hidden field this way:
$hidden_value = param('hidden_name');
Real talk: just like all the other form elements, the value of a hidden field is "sticky". So if you wanna replace a hidden field with some other values after the script has been called once, you'll have to do it manually:
param('hidden_name','new','values','here');
Creating a clickable image button ๐ผ๏ธ
print image_button(-name=>'button_name',
-src=>'/source/URL',
-align=>'MIDDLE');
-or-
print image_button('button_name','/source/URL','MIDDLE');
image_button() produces a clickable image. When it gets clicked, the position of the click is returned to your script as "button_name.x" and "button_name.y", where "button_name" is the name you assigned to it. Coordinates, slay. ๐
Parameters:
- The first argument (
-name) is required and specifies the name of this field. - The second argument (
-src) is also required and specifies the URL - The third option (
-align, optional) is an alignment type, and may beTOP,BOTTOMorMIDDLE
Fetch the value of the button this way:
$x = param('button_name.x');
$y = param('button_name.y');
Creating a javascript action button โก
print button(-name=>'button_name',
-value=>'user visible label',
-onClick=>"do_something()");
-or-
print button('button_name',"user visible value","do_something()");
button() produces an "<input>" tag with "type="button"". When it's pressed, the fragment of JavaScript code pointed to by the -onClick parameter gets executed. Push the button, stuff happens. ๐ฅ
โจ WORKING WITH FRAMES โจ
Okay so bestie, yes โ CGI.pm scripts can absolutely write into multiple browser panels and windows using the HTML 4 frame mechanism. There are like three whole techniques for defining new frames programmatically, and I'm gonna walk you through all of them ๐
1. Create a <Frameset> document
After you've written out the HTTP header, instead of making a standard HTML document with the start_html() call, you create a <frameset> document that defines the frames on the page. Then you specify your script(s) (with the appropriate parameters, obviously) as the SRC for each of the frames.
Ngl, there's no specific support for creating <frameset> sections in CGI.pm, but the HTML is genuinely so simple to write yourself. It's giving DIY but in a cute way ๐
2. Specify the destination for the document in the HTTP header
You can hand the header() method a -target parameter, like this:
print header(-target=>'ResultsWindow');
This tells the browser to load the output of your script into the frame named "ResultsWindow". And if a frame with that name doesn't already exist? The browser just pops up a new window and loads your script's document into that instead. Iconic behaviour honestly.
There are a number of magic names you can use for targets โ go check the HTML "<frame>" documentation for the deets ๐
3. Specify the destination for the document in the <form> tag
You can also specify the frame to load right in the FORM tag itself. With CGI.pm it looks like this:
print start_form(-target=>'ResultsWindow');
So when your script gets reinvoked by the form, its output will be loaded into the frame named "ResultsWindow". Same deal as before โ if one doesn't already exist, a new window gets created. Slay.
The script frameset.cgi in the examples directory shows one way to create pages where the fill-out form and the response live in side-by-side frames. Go look at it, fr fr ๐ซถ
๐ SUPPORT FOR JAVASCRIPT ๐
The usual way to use JavaScript is to define a set of functions in a <SCRIPT> block inside the HTML header, and then register event handlers in the various elements of the page. Events include such things as the mouse passing over a form element, a button being clicked, the contents of a text field changing, or a form being submitted. When an event occurs that involves an element with a registered event handler, its associated JavaScript code gets called. It's giving main character energy for your callbacks ๐
The elements that can register event handlers include the <BODY> of an HTML document, hypertext links, all the various elements of a fill-out form, and the form itself. There are a large number of events, and each one applies only to the elements for which it's relevant. Here's a partial list:
onLoadโ the browser is loading the current document. Valid in:- The HTML
<BODY>section only.
- The HTML
onUnloadโ the browser is closing the current page or frame. Valid for:- The HTML
<BODY>section only.
- The HTML
onSubmitโ the user has pressed the submit button of a form. This event happens just before the form is submitted, and your function can return a value of false in order to abort the submission. Valid for:- Forms only.
onClickโ the mouse has clicked on an item in a fill-out form. Valid for:- Buttons (including submit, reset, and image buttons)
- Checkboxes
- Radio buttons
onChangeโ the user has changed the contents of a field. Valid for:- Text fields
- Text areas
- Password fields
- File fields
- Popup Menus
- Scrolling lists
onFocusโ the user has selected a field to work with. Valid for:- Text fields
- Text areas
- Password fields
- File fields
- Popup Menus
- Scrolling lists
onBlurโ the user has deselected a field (gone to work somewhere else, rude but okay). Valid for:- Text fields
- Text areas
- Password fields
- File fields
- Popup Menus
- Scrolling lists
onSelectโ the user has changed the part of a text field that is selected. Valid for:- Text fields
- Text areas
- Password fields
- File fields
onMouseOverโ the mouse has moved over an element.- Text fields
- Text areas
- Password fields
- File fields
- Popup Menus
- Scrolling lists
onMouseOutโ the mouse has moved off an element.- Text fields
- Text areas
- Password fields
- File fields
- Popup Menus
- Scrolling lists
So to register a JavaScript event handler with an HTML element, you literally just use the event name as a parameter when you call the corresponding CGI method. Periodt.
For example, to have your validateAge() JavaScript code executed every time the textfield named "age" changes, generate the field like this:
print textfield(-name=>'age',-onChange=>"validateAge(this)");
This example assumes you've already declared the validateAge() function by incorporating it into a <SCRIPT> block. And the CGI.pm start_html() method provides a convenient way to create this section, convenient king that it is ๐
Similarly, you can create a form that checks itself over for consistency and alerts the user if some essential value is missing by creating it this way:
print start_form(-onSubmit=>"validateMe(this)");
See the javascript.cgi script for a demonstration of how this all works. Obsessed with a working demo tbh ๐ฆ
๐จ LIMITED SUPPORT FOR CASCADING STYLE SHEETS ๐จ
Real talk: CGI.pm has limited support for HTML3's cascading style sheets (css). To incorporate a stylesheet into your document, pass the start_html() method a -style parameter. The value of this parameter may be a scalar โ in which case it's treated as the source URL for the stylesheet โ or it may be a hash reference. In the hashref case you should provide the hash with one or more of -src or -code.
-srcpoints to a URL where an externally-defined stylesheet can be found.-codepoints to a scalar value to be incorporated into a<style>section.
Style definitions in -code override similarly-named ones in -src, hence the name "cascading." Cute how that works ๐
You may also specify the type of the stylesheet by adding the optional -type parameter to the hash pointed to by -style. If not specified, the style defaults to 'text/css'.
To refer to a style within the body of your document, add the -class parameter to any HTML element:
print h1({-class=>'Fancy'},'Welcome to the Party');
Or define styles on the fly with the -style parameter:
print h1({-style=>'Color: red;'},'Welcome to Hell');
You may also use the new span() element to apply a style to a section of text:
print span({-style=>'Color: red;'},
h1('Welcome to Hell'),
"Where did that handbasket get to?"
);
Heads up bestie: you must import the":html3"definitions to have thespan()method available. Don't come for me when it's undefined, I warned you ๐ญ
Here's a quick and dirty example of using CSS's. See the CSS specification at http://www.w3.org/Style/CSS/ for more information.
use CGI qw/:standard :html3/;
#here's a stylesheet incorporated directly into the page
$newStyle=<<END;
<!--
P.Tip {
margin-right: 50pt;
margin-left: 50pt;
color: red;
}
P.Alert {
font-size: 30pt;
font-family: sans-serif;
color: red;
}
-->
END
print header();
print start_html( -title=>'CGI with Style',
-style=>{-src=>'http://www.capricorn.com/style/st1.css',
-code=>$newStyle}
);
print h1('CGI with Style'),
p({-class=>'Tip'},
"Better read the cascading style sheet spec before playing with this!"),
span({-style=>'color: magenta'},
"Look Mom, no hands!",
p(),
"Whooo wee!"
);
print end_html;
Pass an array reference to -code or -src in order to incorporate multiple stylesheets into your document. More is more, always โจ
Should you wish to incorporate a verbatim stylesheet that includes arbitrary formatting in the header, you may pass a -verbatim tag to the -style hash, as follows:
print start_html (-style => {-verbatim => '@import url("/server-common/css/'.$cssFile.'");',
-src => '/server-common/css/core.css'});
This will generate an HTML header that contains this:
<link rel="stylesheet" type="text/css" href="/server-common/css/core.css">
<style type="text/css">
@import url("/server-common/css/main.css");
</style>
Any additional arguments passed in the -style value will be incorporated into the <link> tag. For example:
start_html(-style=>{-src=>['/styles/print.css','/styles/layout.css'],
-media => 'all'});
This will give:
<link rel="stylesheet" type="text/css" href="/styles/print.css" media="all"/>
<link rel="stylesheet" type="text/css" href="/styles/layout.css" media="all"/>
<p>
To make more complicated <link> tags, use the Link() function and pass it to start_html() in the -head argument, as in:
@h = (Link({-rel=>'stylesheet',-type=>'text/css',-src=>'/ss/ss.css',-media=>'all'}),
Link({-rel=>'stylesheet',-type=>'text/css',-src=>'/ss/fred.css',-media=>'paper'}));
print start_html({-head=>\@h})
To create primary and "alternate" stylesheet, use the -alternate option:
start_html(-style=>{-src=>[
{-src=>'/styles/print.css'},
{-src=>'/styles/alt.css',-alternate=>1}
]
});
๐ Dumping out all the name/value pairs
The Dump() method produces a string consisting of all the query's name/value pairs formatted nicely as a nested list. This is useful for debugging purposes:
print Dump
Produces something that looks like:
<ul>
<li>name1
<ul>
<li>value1
<li>value2
</ul>
<li>name2
<ul>
<li>value1
</ul>
</ul>
As a shortcut, you can interpolate the entire CGI object into a string and it will be replaced with the a nice HTML dump shown above:
$q=CGI->new;
print "<h2>Current Values</h2> $q\n";
๐ BUGS ๐
Address bug reports and comments to: <https://github.com/leejo/CGI.pm/issues>
See the <https://github.com/leejo/CGI.pm/blob/master/CONTRIBUTING.md> file for information on raising issues and contributing ๐ซถ
The original bug tracker can be found at: <https://rt.cpan.org/Public/Dist/Display.html?Queue=CGI.pm>
Found a bug? Don't suffer in silence bestie, file that issue ๐ธ
๐ฆ SEE ALSO ๐ฆ
Okay bestie, you want the receipts? ๐ Here's where all of this literally comes from:
CGIโ the actual original source of this documentation / functionality, no cap. It's the mothership, the main character, the whole reason we're here. Go give it a lil visit. ๐ซถ
And that's a wrap on the entire page, bestie!! ๐ You made it to the very end and that is iconic behavior, fr fr. ๐
Real talk though โ this whole thing is filed under CGI::HT...nctions(3) from perl v5.42.0, dated 2025-01-09 (yes the name gets truncated, and honestly? we just live with it ๐ญ). That's the source, that's the version, that's the date โ screenshot it, cite it, frame it. ๐
Now go forth and build something cute with it. mwah ๐โจ
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-CGI 4.670.0-160000.2.2 ยท Artistic-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms