CGI
view release on metacpan or search on metacpan
as should (RT #91136)
[ DOCUMENTATION ]
- tweak perldoc for -utf8 option (RT #54341, thanks to Helmut Richter)
- explain the HTML generation functions should no longer be used and that
they may be deprecated in a future release
4.03 2014-07-02
[ REMOVED / DEPRECATIONS ]
- the -multiple option to popup_menu is now IGNORED as this did not
function correctly. If you require a menu with multiple selections
use the scrolling_list method. (RT #30057)
[ SPEC / BUG FIXES ]
- support redirects in mod_perl2, or fall back to using env variable
for up to 5 redirects, when getting the query string (RT #36312)
- CGI::Cookie now correctly supports the -max-age argument, previously
if this was passed the value of the -expires argument would be used
meaning there was no way to supply *only* this argument (RT #50576)
- make :all actually import all methods, except for :cgi-lib, and add
2. Automated tests for hidden() have been added, thanks to Russel Jenkins and Mark Stosberg (RT#20436)
3. t/util.t has been updated to use Test::More instead of a home-grown test function. Thanks to Bob Kuo.
Version 3.45, Aug 14, 2009
[BUG FIXES]
1. Prevent warnings about "uninitialized values" for REQUEST_URI, HTTP_USER_AGENT and other environment variables.
Patches by Callum Gibson, heiko and Mark Stosberg. (RT#24684, RT#29065)
2. Avoid death in some cases when running under Taint mode on Windows.
Patch by Peter Hancock (RT#43796)
3. Allow 0 to be used as a default value in popup_menu(). This was broken starting in 3.37.
Thanks to Haze, who was the first to report this and supply a patch, and pfschill, who pinpointed
when the bug was introduced. A regression test for this was also added. (RT#37908)
4. Allow "+" as a valid character in file names, which fixes temp file creation on OS X Leopard.
Thanks to Andy Armstrong, and alech for patches. (RT#30504)
5. Set binmode() on the Netware platform, thanks to Guenter Knauf (RT#27455)
6. Don't allow a CGI::Carp error handler to die recursively. Print a warning and exit instead.
Thanks to Marc Chantreux. (RT#45956)
7. The Dump() method now is fixed to escape HTML properly. Thanks to Mark Stosberg (RT#21341)
8. Support for <optgroup> with scrolling_list() now works the same way as it does for popup_menu().
Thanks to Stuart Johnston (RT#30097)
9. CGI::Pretty now works properly when $" is set to ''. Thanks to Jim Keenan (RT#12401)
10. Fix crash when used in combination with PerlEx::DBI. Thanks to Burak G�rsoy (RT#19902)
[DOCUMENTATION]
1. Several typos were fixed, Thanks to ambs. (RT#41105)
2. A typo related to the nosticky pragma was fixed, thanks to Britton Kerin. (RT#43220)
3. examples/nph-clock.cgi is now more portable, by calling localtime() rather than `/bin/date`,
thanks to Guenter Knauf. (RT#27456).
4. In CGI::Carp, the SEE ALSO section was cleaned up, thanks to Slaven Rezic. (RT#32769)
5. The docs for redirect() were updated to reflect that most headers are
ignored during redirection. Thanks to Mark Stosberg (RT#44911)
[INTERNALS]
1. New t/unescapeHTML.t test script has been added. It includes a TODO test for a pre-existing
bug which could use a patch. Thanks to Pete Gamache and Mark Stosberg (RT#39122)
2. New test scripts have been added for user_agent(), popup_menu() and query_string(), scrolling_list() and Dump()
Thanks to Mark Stosberg and Stuart Johnston. (RT#37908, RT#43006, RT#21341, RT#30097)
3. CGI::Carp and CGI::Util have been updated to have non-developer version numbers.
Thanks to Slaven Rezic. (RT#48425)
4. CGI::Switch and CGI::Apache now properly set their VERSION in their own name space.
Thanks to Alexey Tourbin (RT#11941,RT#11942)
Version 3.44, Jul 30, 2009
1. Patch from Kurt Jaeger to allow HTTP PUT even if the content length is unknown.
2. Patch from Pavel merdin to fix a problem for one of the FireFox addons.
3. Fix script_name() call from Stephane Chazelas.
Version 3.39, Jun 29, 2008
1. Fixed regression in "exists" function when using tied interface to CGI via $q->Vars.
Version 3.38, Jun 25, 2008
1. Fix annoying warning in http://rt.cpan.org/Ticket/Display.html?id=34551
2. Added nobr() function http://rt.cpan.org/Ticket/Display.html?id=35377
3. popup_menu() allows multiple items to be selected by default, satisfying
http://rt.cpan.org/Ticket/Display.html?id=35376
4. Patch from Renee Backer to avoid doubled <http-equiv> headers.
5. Fixed documentation bug that describes what happens when a
parameter is empty (e.g. "?test1=").
6. Fixed minor warning described at http://rt.cpan.org/Public/Bug/Display.html?id=36435
7. Fixed overlap of attribute and parameter space described in http://rt.perl.org/rt3//Ticket/Display.html?id=24294
Version 3.37, Apr 22, 2008
1. Fix pragmas so that they persist over modperl invocations (e.g. RT 34761)
31. Fixed url_param(), which wasn't working at all.
32. Fixed variable suicide problem in s///e expressions, where the
autoloader was needed during evaluation.
33. Removed excess spaces between elements of checkbox and radio
groups
34. Can now create "valueless" submit buttons
35. Can now set path_info as well as read it.
36. ReadParse() now returns a useful function result.
37. import_names() now allows you to optionally clear out the
namespace before importing (for mod_perl users)
38. Made it possible to have a popup menu or radio button with a value
of "0".
39. link() changed to Link() to avoid overriding native link function.
40. Takes advantage of mod_perl's register_cleanup() function to clear
globals.
41. <LAYER> and <ILAYER> added to :html3 functions.
42. Fixed problems with private tempfiles and NT/IIS systems.
43. No longer prints the DTD by default (I bet no one will complain).
44. Allow underscores to replace internal hyphens in parameter names.
45. CGI::Push supports heterogeneous MIME types and adjustable delays
between pages.
script to a file or pipe.
3. An improved version of the new() method that allows you to restore
the state of a script from a file or pipe. With (2) this gives you
dump and restore capabilities! (Wow, you can put a "121,931
customers served" banner at the bottom of your pages!)
4. A self_url() method that allows you to create state-maintaining
hypertext links. In addition to allowing you to maintain the state
of your scripts between invocations, this lets you work around a
problem that some browsers have when jumping to internal links in
a document that contains a form -- the form information gets lost.
5. The user-visible labels in checkboxes, radio buttons, popup menus
and scrolling lists have now been decoupled from the values sent
to your CGI script. Your script can know a checkbox by the name of
"cb1" while the user knows it by a more descriptive name. I've
also added some parameters that were missing from the text fields,
such as MAXLENGTH.
6. A whole bunch of methods have been added to get at environment
variables involved in user verification and other obscure
features.
Bug fixes
t/html_functions.t
t/http.t
t/init.t
t/init_test.txt
t/multipart_globals.t
t/multipart_init.t
t/multipart_start.t
t/no_tabindex.t
t/param_fetch.t
t/param_list_context.t
t/popup_menu.t
t/postdata.t
t/pretty.t
t/push.t
t/query_string.t
t/redirect_query_string.t
t/request.t
t/rt-31107.t
t/rt-52469.t
t/rt-57524.t
t/rt-75628.t
div table caption th td TR Tr sup Sub strike applet Param nobr
embed basefont style span layer ilayer font frameset frame script small big Area Map
/ ],
':html4' => [ qw/
abbr acronym bdo col colgroup del fieldset iframe
ins label legend noframes noscript object optgroup Q
thead tbody tfoot
/ ],
':form' => [ qw/
textfield textarea filefield password_field hidden checkbox checkbox_group
submit reset defaults radio_group popup_menu button autoEscape
scrolling_list image_button start_form end_form
start_multipart_form end_multipart_form isindex tmpFileName uploadInfo URL_ENCODED MULTIPART
/ ],
':cgi' => [ qw/
param multi_param upload path_info path_translated request_uri url self_url script_name
cookie Dump raw_cookie request_method query_string Accept user_agent remote_host content_type
remote_addr referer server_name server_software server_port server_protocol virtual_port
virtual_host remote_ident auth_type http append save_parameters restore_parameters param_fetch
remote_user user_name header redirect import_names put Delete Delete_all url_param cgi_error env_query_string
/ ],
} else {
push(@elements,qq/<input type="$box_type" name="$name" value="$_" $checkit$other$tab$attribs$disable>${label}${break}/);
}
}
$self->register_parameter($name);
return wantarray ? @elements : "@elements"
unless defined($columns) || defined($rows);
return _tableize($rows,$columns,$rowheaders,$colheaders,@elements);
}
#### Method: popup_menu
# Create a popup menu.
# Parameters:
# $name -> Name for all the menu
# $values -> A pointer to a regular array containing the
# text of each menu item.
# $default -> (optional) Default item to display
# $labels -> (optional)
# A pointer to a hash of labels to print next to each checkbox
# in the form $label{'value'}="Long explanatory label".
# Otherwise the provided values are used as the labels.
# Returns:
# A string containing the definition of a popup menu.
####
sub popup_menu {
my($self,@p) = self_or_default(@_);
my($name,$values,$default,$labels,$attributes,$override,$tabindex,@other) =
rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS,
ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p);
my($result,%selected);
if (!$override && defined($self->param($name))) {
$selected{$self->param($name)}++;
} elsif (defined $default) {
lib/CGI/HTML/Functions.pod view on Meta::CPAN
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>
lib/CGI/HTML/Functions.pod view on Meta::CPAN
The optional fourth parameter is the maximum number of characters the
field will accept (-maxlength).
=back
JAVASCRIPTING: The B<-onChange>, B<-onFocus>, B<-onBlur>,
B<-onMouseOver>, B<-onMouseOut> and B<-onSelect> parameters are
recognized. See textfield() for details.
=head2 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);
-or (named parameter style)-
print popup_menu(-name=>'menu_name',
-values=>['eenie','meenie','minie'],
-default=>['meenie','minie'],
-labels=>\%labels,
-attributes=>\%attributes);
popup_menu() creates a menu. Please note that the -multiple option will be
ignored if passed - use scrolling_list() if you want to create a menu that
supports multiple selections
=over 4
=item 1.
The required first argument is the menu's name (-name).
=item 2.
lib/CGI/HTML/Functions.pod view on Meta::CPAN
The optional third parameter (-default) is the name of the default
menu choice. If not specified, the first item will be the default.
The values of the previous choice will be maintained across
queries. Pass an array reference to select multiple defaults.
=item 4.
The optional fourth parameter (-labels) is provided for people who
want to use different values for the user-visible label inside the
popup menu and the value returned to your script. It's a pointer to an
hash relating menu values to user-visible labels. If you
leave this parameter blank, the menu values will be displayed by
default. (You can also leave a label undefined if you want to).
=item 5.
The optional fifth 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.
=back
When the form is processed, the selected value of the popup menu can
be retrieved using:
$popup_menu_value = param('menu_name');
=head2 Creating an option group
Named parameter style
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');
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.
=over 4
=item 1.
The required first argument (B<-name>) is the label attribute of the
optgroup and is B<not> inserted in the parameter list of the query.
=item 2.
lib/CGI/HTML/Functions.pod view on Meta::CPAN
scrolling_list() creates a scrolling list.
B<Parameters:>
=over 4
=item 1.
The first and second arguments are the list name (-name) and values
(-values). As in the popup menu, the second argument should be an
array reference.
=item 2.
The optional third argument (-default) can be either a reference to a
list containing the values to be selected by default, or can be a
single value to select. If this argument is missing or undefined,
then nothing is selected when the list first appears. In the named
parameter version, you can use the synonym "-defaults" for this
parameter.
lib/CGI/HTML/Functions.pod view on Meta::CPAN
checkbox_group() creates a list of checkboxes that are related
by the same name.
B<Parameters:>
=over 4
=item 1.
The first and second arguments are the checkbox name and values,
respectively (-name and -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.
=item 2.
The optional third argument (-default) can be either a reference to a
list containing the values to be checked by default, or can be a
single value to checked. If this argument is missing or undefined,
then nothing is selected when the list first appears.
t/autoescape.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use Test::More tests => 18;
use CGI qw/ autoEscape escapeHTML button textfield password_field textarea popup_menu scrolling_list checkbox_group optgroup checkbox radio_group submit image_button button /;
is (button(-name => 'test<'), '<input type="button" name="test<" value="test<" />', "autoEscape defaults to On");
my $before = escapeHTML("test<");
autoEscape(undef);
my $after = escapeHTML("test<");
is($before, "test<", "reality check escapeHTML");
t/autoescape.t view on Meta::CPAN
default => 'text area',
rows => 10,
columns => 50,
onclick => 'alert("===> text area")',
},
),
qq{<textarea name="foo" rows="10" cols="50" onclick="alert("===> text area")">text area</textarea>},
'autoescape javascript turns off for textarea'
);
is(popup_menu(
{
name => 'menu_name',
values => ['eenie','meenie','minie'],
default => 'meenie',
onclick => 'alert("===> popup menu")',
}
),
qq{<select name="menu_name" onclick="alert("===> popup menu")">
<option value="eenie">eenie</option>
<option selected="selected" value="meenie">meenie</option>
<option value="minie">minie</option>
</select>},
'autoescape javascript turns off for popup_menu'
);
is(popup_menu(
-name=>'menu_name',
onclick => 'alert("===> menu group")',
-values=>[
qw/eenie meenie minie/,
optgroup(
-name=>'optgroup_name',
onclick =>
'alert("===> menu group option")',
-values => ['moe','catch'],
-attributes=>{'catch'=>{'class'=>'red'}}
t/autoescape.t view on Meta::CPAN
),
qq{<select name="menu_name" onclick="alert("===> menu group")">
<option value="eenie">one</option>
<option selected="selected" value="meenie">two</option>
<option value="minie">three</option>
<optgroup label="optgroup_name" onclick="alert("===> menu group option")">
<option value="moe">moe</option>
<option class="red" value="catch">catch</option>
</optgroup>
</select>},
'autoescape javascript turns off for popup_menu #2'
);
is(scrolling_list(
-name=>'list_name',
onclick => 'alert("===> scrolling
list")',
-values=>['eenie','meenie','minie','moe'],
-default=>['eenie','moe'],
-size=>5,
-multiple=>'true',
qq(<label><input type="checkbox" name="game" value="checkers" checked="checked" tabindex="15" />checkers</label> <label><input type="checkbox" name="game" value="chess" checked="checked" tabindex="16" />chess</label> <label><input type="checkbox" ...
'checkbox_group()');
is(checkbox_group(-name => 'game',
'-values' => [qw/checkers chess cribbage/],
'-defaults' => ['cribbage'],
-override=>1),
qq(<label><input type="checkbox" name="game" value="checkers" tabindex="18" />checkers</label> <label><input type="checkbox" name="game" value="chess" tabindex="19" />chess</label> <label><input type="checkbox" name="game" value="cribbage" checked...
'checkbox_group()');
is(popup_menu(-name => 'game',
'-values' => [qw/checkers chess cribbage/],
-default => 'cribbage',
-override => 1),
'<select name="game" tabindex="21" >
<option value="checkers">checkers</option>
<option value="chess">chess</option>
<option selected="selected" value="cribbage">cribbage</option>
</select>',
'popup_menu()');
is(scrolling_list(-name => 'game',
'-values' => [qw/checkers chess cribbage/],
-default => 'cribbage',
-override=>1),
'<select name="game" tabindex="22" size="3">
<option value="checkers">checkers</option>
<option value="chess">chess</option>
<option selected="selected" value="cribbage">cribbage</option>
</select>',
'scrolling_list()');
-Values => ['moe','catch'],
-attributes=>{'catch'=>{'class'=>'red'}});
is($optgroup,
qq(<optgroup label="optgroup_name">
<option value="moe">moe</option>
<option class="red" value="catch">catch</option>
</optgroup>),
'optgroup()');
is(popup_menu(-name=>'menu_name',
-Values=>[qw/eenie meenie minie/, $optgroup],
-labels=>{'eenie'=>'one',
'meenie'=>'two',
'minie'=>'three'},
-default=>'meenie'),
qq(<select name="menu_name" tabindex="26" >
<option value="eenie">one</option>
<option selected="selected" value="meenie">two</option>
<option value="minie">three</option>
<optgroup label="optgroup_name">
<option value="moe">moe</option>
<option class="red" value="catch">catch</option>
</optgroup>
</select>),
'popup_menu() + optgroup()');
is(scrolling_list(-name=>'menu_name',
-Values=>[qw/eenie meenie minie/, $optgroup],
-labels=>{'eenie'=>'one',
'meenie'=>'two',
'minie'=>'three'},
-default=>'meenie'),
qq(<select name="menu_name" tabindex="27" size="4">
<option value="eenie">one</option>
<option selected="selected" value="meenie">two</option>
t/no_tabindex.t view on Meta::CPAN
qq(<label><input type="checkbox" name="game" value="checkers" checked="checked" />checkers</label> <label><input type="checkbox" name="game" value="chess" checked="checked" />chess</label> <label><input type="checkbox" name="game" value="cribbage"...
'checkbox_group()');
is(checkbox_group(-name => 'game',
'-values' => [qw/checkers chess cribbage/],
'-defaults' => ['cribbage'],
-override=>1),
qq(<label><input type="checkbox" name="game" value="checkers" />checkers</label> <label><input type="checkbox" name="game" value="chess" />chess</label> <label><input type="checkbox" name="game" value="cribbage" checked="checked" />cribbage</label...
'checkbox_group()');
is(popup_menu(-name => 'game',
'-values' => [qw/checkers chess cribbage/],
-default => 'cribbage',
-override => 1),
'<select name="game" >
<option value="checkers">checkers</option>
<option value="chess">chess</option>
<option selected="selected" value="cribbage">cribbage</option>
</select>',
'popup_menu()');
is(textarea(-name=>'foo',
-default=>'starting value',
-rows=>10,
-columns=>50),
'<textarea name="foo" rows="10" cols="50">starting value</textarea>',
'textarea()');
t/popup_menu.t view on Meta::CPAN
#!perl
# Tests for popup_menu();
use Test::More 'no_plan';
use CGI;
my $q = CGI->new;
is ( $q->popup_menu(-name=>"foo", - values=>[0,1], -default=>0),
'<select name="foo" >
<option selected="selected" value="0">0</option>
<option value="1">1</option>
</select>'
, 'popup_menu(): basic test, including 0 as a default value');
is(
CGI::popup_menu(-values=>[CGI::optgroup(-values=>["b+"])],-default=>"b+"),
'<select name="" >
<optgroup label="">
<option selected="selected" value="b+">b+</option>
</optgroup>
</select>'
, "<optgroup> selections work when the default values contain regex characters (RT#49606)");
unlike(
$q->popup_menu(
-name =>"foo",
-values =>[0,1],
-multiple => 'true',
-MULTIPLE => 'true',
),
qr/multiple/,
'popup_menu ignores -multiple option',
);
( run in 2.435 seconds using v1.01-cache-2.11-cpan-364913b4093 )