");
return join("\n",@result);
}
#### Method as_string
#
# synonym for "dump"
####
sub as_string {
&Dump(@_);
}
#### Method: save
# Write values out to a filehandle in such a way that they can
# be reinitialized by the filehandle form of the new() method
####
sub save {
my($self,$filehandle) = self_or_default(@_);
$filehandle = to_filehandle($filehandle);
my($param);
local($,) = ''; # set print field separator back to a sane value
local($\) = ''; # set output line separator to a sane value
for $param ($self->param) {
my($escaped_param) = escape($param);
my($value);
for $value ($self->param($param)) {
print $filehandle "$escaped_param=",escape("$value"),"\n"
if length($escaped_param) or length($value);
}
}
for (keys %{$self->{'.fieldnames'}}) {
print $filehandle ".cgifields=",escape("$_"),"\n";
}
print $filehandle "=\n"; # end of record
}
#### Method: save_parameters
# An alias for save() that is a better name for exportation.
# Only intended to be used with the function (non-OO) interface.
####
sub save_parameters {
my $fh = shift;
return save(to_filehandle($fh));
}
#### Method: restore_parameters
# A way to restore CGI parameters from an initializer.
# Only intended to be used with the function (non-OO) interface.
####
sub restore_parameters {
$Q = $CGI::DefaultClass->new(@_);
}
#### Method: multipart_init
# Return a Content-Type: style header for server-push
# This has to be NPH on most web servers, and it is advisable to set $| = 1
#
# Many thanks to Ed Jordan for this
# contribution, updated by Andrew Benham (adsb@bigfoot.com)
####
sub multipart_init {
my($self,@p) = self_or_default(@_);
my($boundary,$charset,@other) = rearrange_header([BOUNDARY,CHARSET],@p);
if (!$boundary) {
$boundary = '------- =_';
my @chrs = ('0'..'9', 'A'..'Z', 'a'..'z');
for (1..17) {
$boundary .= $chrs[rand(scalar @chrs)];
}
}
$self->{'separator'} = "$CRLF--$boundary$CRLF";
$self->{'final_separator'} = "$CRLF--$boundary--$CRLF";
$type = SERVER_PUSH($boundary);
return $self->header(
-nph => 0,
-type => $type,
-charset => $charset,
(map { split "=", $_, 2 } @other),
) . "WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY." . $self->multipart_end;
}
#### Method: multipart_start
# Return a Content-Type: style header for server-push, start of section
#
# Many thanks to Ed Jordan for this
# contribution, updated by Andrew Benham (adsb@bigfoot.com)
####
sub multipart_start {
my(@header);
my($self,@p) = self_or_default(@_);
my($type,$charset,@other) = rearrange([TYPE,CHARSET],@p);
$type = $type || 'text/html';
if ($charset) {
push(@header,"Content-Type: $type; charset=$charset");
} else {
push(@header,"Content-Type: $type");
}
# rearrange() was designed for the HTML portion, so we
# need to fix it up a little.
for (@other) {
# Don't use \s because of perl bug 21951
next unless my($header,$value) = /([^ \r\n\t=]+)=\"?(.+?)\"?$/;
($_ = $header) =~ s/^(\w)(.*)/$1 . lc ($2) . ': '.$self->unescapeHTML($value)/e;
}
push(@header,@other);
my $header = join($CRLF,@header)."${CRLF}${CRLF}";
return $header;
}
#### Method: multipart_end
# Return a MIME boundary separator for server-push, end of section
#
# Many thanks to Ed Jordan for this
# contribution
####
sub multipart_end {
my($self,@p) = self_or_default(@_);
return $self->{'separator'};
}
#### Method: multipart_final
# Return a MIME boundary separator for server-push, end of all sections
#
# Contributed by Andrew Benham (adsb@bigfoot.com)
####
sub multipart_final {
my($self,@p) = self_or_default(@_);
return $self->{'final_separator'} . "WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY." . $CRLF;
}
#### Method: header
# Return a Content-Type: style header
#
####
sub header {
my($self,@p) = self_or_default(@_);
my(@header);
return "" if $self->{'.header_printed'}++ and $HEADERS_ONCE;
my($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other) =
rearrange([['TYPE','CONTENT_TYPE','CONTENT-TYPE'],
'STATUS',['COOKIE','COOKIES','SET-COOKIE'],'TARGET',
'EXPIRES','NPH','CHARSET',
'ATTACHMENT','P3P'],@p);
# Since $cookie and $p3p may be array references,
# we must stringify them before CR escaping is done.
my @cookie;
for (ref($cookie) eq 'ARRAY' ? @{$cookie} : $cookie) {
my $cs = UNIVERSAL::isa($_,'CGI::Cookie') ? $_->as_string : $_;
push(@cookie,$cs) if defined $cs and $cs ne '';
}
$p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
# CR escaping for values, per RFC 822
for my $header ($type,$status,@cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other) {
if (defined $header) {
# From RFC 822:
# Unfolding is accomplished by regarding CRLF immediately
# followed by a LWSP-char as equivalent to the LWSP-char.
$header =~ s/$CRLF(\s)/$1/g;
# All other uses of newlines are invalid input.
if ($header =~ m/$CRLF|\015|\012/) {
# shorten very long values in the diagnostic
$header = substr($header,0,72).'...' if (length $header > 72);
die "Invalid header value contains a newline not followed by whitespace: $header";
}
}
}
$nph ||= $NPH;
$type ||= 'text/html' unless defined($type);
# sets if $charset is given, gets if not
$charset = $self->charset( $charset );
# rearrange() was designed for the HTML portion, so we
# need to fix it up a little.
for (@other) {
# Don't use \s because of perl bug 21951
next unless my($header,$value) = /([^ \r\n\t=]+)=\"?(.+?)\"?$/s;
($_ = $header) =~ s/^(\w)(.*)/"\u$1\L$2" . ': '.$self->unescapeHTML($value)/e;
}
$type .= "; charset=$charset"
if $type ne ''
and $type !~ /\bcharset\b/
and defined $charset
and $charset ne '';
# Maybe future compatibility. Maybe not.
my $protocol = $ENV{SERVER_PROTOCOL} || 'HTTP/1.0';
push(@header,$protocol . ' ' . ($status || '200 OK')) if $nph;
push(@header,"Server: " . &server_software()) if $nph;
push(@header,"Status: $status") if $status;
push(@header,"Window-Target: $target") if $target;
push(@header,"P3P: policyref=\"/w3c/p3p.xml\", CP=\"$p3p\"") if $p3p;
# push all the cookies -- there may be several
push(@header,map {"Set-Cookie: $_"} @cookie);
# if the user indicates an expiration time, then we need
# both an Expires and a Date header (so that the browser is
# uses OUR clock)
push(@header,"Expires: " . expires($expires,'http'))
if $expires;
push(@header,"Date: " . expires(0,'http')) if $expires || $cookie || $nph;
push(@header,"Pragma: no-cache") if $self->cache();
push(@header,"Content-Disposition: attachment; filename=\"$attachment\"") if $attachment;
push(@header,map {ucfirst $_} @other);
push(@header,"Content-Type: $type") if $type ne '';
my $header = join($CRLF,@header)."${CRLF}${CRLF}";
if (($MOD_PERL >= 1) && !$nph) {
$self->r->send_cgi_header($header);
return '';
}
return $header;
}
#### Method: cache
# Control whether header() will produce the no-cache
# Pragma directive.
####
sub cache {
my($self,$new_value) = self_or_default(@_);
$new_value = '' unless $new_value;
if ($new_value ne '') {
$self->{'cache'} = $new_value;
}
return $self->{'cache'};
}
#### Method: redirect
# Return a Location: style header
#
####
sub redirect {
my($self,@p) = self_or_default(@_);
my($url,$target,$status,$cookie,$nph,@other) =
rearrange([[LOCATION,URI,URL],TARGET,STATUS,['COOKIE','COOKIES','SET-COOKIE'],NPH],@p);
$status = '302 Found' unless defined $status;
$url ||= $self->self_url;
my(@o);
for (@other) { tr/\"//d; push(@o,split("=",$_,2)); }
unshift(@o,
'-Status' => $status,
'-Location'=> $url,
'-nph' => $nph);
unshift(@o,'-Target'=>$target) if $target;
unshift(@o,'-Type'=>'');
my @unescaped;
unshift(@unescaped,'-Cookie'=>$cookie) if $cookie;
return $self->header((map {$self->unescapeHTML($_)} @o),@unescaped);
}
#### Method: start_html
# Canned HTML header
#
# Parameters:
# $title -> (optional) The title for this HTML document (-title)
# $author -> (optional) e-mail address of the author (-author)
# $base -> (optional) if set to true, will enter the BASE address of this document
# for resolving relative references (-base)
# $xbase -> (optional) alternative base at some remote location (-xbase)
# $target -> (optional) target window to load all links into (-target)
# $script -> (option) Javascript code (-script)
# $no_script -> (option) Javascript
END
;
my($other) = @other ? " @other" : '';
push(@result,"\n\n");
return join("\n",@result);
}
### Method: _style
# internal method for generating a CSS style section
####
sub _style {
my ($self,$style) = @_;
my (@result);
my $type = 'text/css';
my $rel = 'stylesheet';
my $cdata_start = $XHTML ? "\n\n" : " -->\n";
my @s = ref($style) eq 'ARRAY' ? @$style : $style;
my $other = '';
for my $s (@s) {
if (ref($s)) {
my($src,$code,$verbatim,$stype,$alternate,$foo,@other) =
rearrange([qw(SRC CODE VERBATIM TYPE ALTERNATE FOO)],
('-foo'=>'bar',
ref($s) eq 'ARRAY' ? @$s : %$s));
my $type = defined $stype ? $stype : 'text/css';
my $rel = $alternate ? 'alternate stylesheet' : 'stylesheet';
$other = "@other" if @other;
if (ref($src) eq "ARRAY") # Check to see if the $src variable is an array reference
{ # If it is, push a LINK tag for each one
for $src (@$src)
{
push(@result,$XHTML ? qq()
: qq()) if $src;
}
}
else
{ # Otherwise, push the single -src, if it exists.
push(@result,$XHTML ? qq()
: qq()
) if $src;
}
if ($verbatim) {
my @v = ref($verbatim) eq 'ARRAY' ? @$verbatim : $verbatim;
push(@result, "") for @v;
}
if ($code) {
my @c = ref($code) eq 'ARRAY' ? @$code : $code;
push(@result,style({'type'=>$type},"$cdata_start\n$_\n$cdata_end")) for @c;
}
} else {
my $src = $s;
push(@result,$XHTML ? qq()
: qq());
}
}
@result;
}
sub _script {
my ($self,$script) = @_;
my (@result);
my (@scripts) = ref($script) eq 'ARRAY' ? @$script : ($script);
for $script (@scripts) {
my($src,$code,$language,$charset);
if (ref($script)) { # script is a hash
($src,$code,$type,$charset) =
rearrange(['SRC','CODE',['LANGUAGE','TYPE'],'CHARSET'],
'-foo'=>'bar', # a trick to allow the '-' to be omitted
ref($script) eq 'ARRAY' ? @$script : %$script);
$type ||= 'text/javascript';
unless ($type =~ m!\w+/\w+!) {
$type =~ s/[\d.]+$//;
$type = "text/$type";
}
} else {
($src,$code,$type,$charset) = ('',$script, 'text/javascript', '');
}
my $comment = '//'; # javascript by default
$comment = '#' if $type=~/perl|tcl/i;
$comment = "'" if $type=~/vbscript/i;
my ($cdata_start,$cdata_end);
if ($XHTML) {
$cdata_start = "$comment";
} else {
$cdata_start = "\n\n";
}
my(@satts);
push(@satts,'src'=>$src) if $src;
push(@satts,'type'=>$type);
push(@satts,'charset'=>$charset) if ($src && $charset);
$code = $cdata_start . $code . $cdata_end if defined $code;
push(@result,$self->script({@satts},$code || ''));
}
@result;
}
#### Method: end_html
# End an HTML document.
# Trivial method for completeness. Just returns ""
####
sub end_html {
return "\n\n";
}
################################
# METHODS USED IN BUILDING FORMS
################################
#### Method: isindex
# Just prints out the isindex tag.
# Parameters:
# $action -> optional URL of script to run
# Returns:
# A string containing a tag
sub isindex {
my($self,@p) = self_or_default(@_);
my($action,@other) = rearrange([ACTION],@p);
$action = qq/ action="$action"/ if $action;
my($other) = @other ? " @other" : '';
return $XHTML ? "" : "";
}
#### Method: start_form
# Start a form
# Parameters:
# $method -> optional submission method to use (GET or POST)
# $action -> optional URL of script to run
# $enctype ->encoding to use (URL_ENCODED or MULTIPART)
sub start_form {
my($self,@p) = self_or_default(@_);
my($method,$action,$enctype,@other) =
rearrange([METHOD,ACTION,ENCTYPE],@p);
$method = $self->_maybe_escapeHTML(lc($method || 'post'));
if( $XHTML ){
$enctype = $self->_maybe_escapeHTML($enctype || &MULTIPART);
}else{
$enctype = $self->_maybe_escapeHTML($enctype || &URL_ENCODED);
}
if (defined $action) {
$action = $self->_maybe_escapeHTML($action);
}
else {
$action = $self->_maybe_escapeHTML($self->request_uri || $self->self_url);
}
$action = qq(action="$action");
my($other) = @other ? " @other" : '';
$self->{'.parametersToAdd'}={};
return qq/") : "\n";
} else {
if (my @fields = $self->get_fields) {
return wantarray ? ("
",@fields,"
","")
: "
".(join '',@fields)."
\n";
} else {
return "";
}
}
}
#### Method: end_multipart_form
# end a multipart form
sub end_multipart_form {
&end_form;
}
sub _textfield {
my($self,$tag,@p) = self_or_default(@_);
my($name,$default,$size,$maxlength,$override,$tabindex,@other) =
rearrange([NAME,[DEFAULT,VALUE,VALUES],SIZE,MAXLENGTH,[OVERRIDE,FORCE],TABINDEX],@p);
my $current = $override ? $default :
(defined($self->param($name)) ? $self->param($name) : $default);
$current = defined($current) ? $self->_maybe_escapeHTML($current,1) : '';
$name = defined($name) ? $self->_maybe_escapeHTML($name) : '';
my($s) = defined($size) ? qq/ size="$size"/ : '';
my($m) = defined($maxlength) ? qq/ maxlength="$maxlength"/ : '';
my($other) = @other ? " @other" : '';
# this entered at cristy's request to fix problems with file upload fields
# and WebTV -- not sure it won't break stuff
my($value) = $current ne '' ? qq(value="$current") : '';
$tabindex = $self->element_tab($tabindex);
return $XHTML ? qq()
: qq();
}
#### Method: textfield
# Parameters:
# $name -> Name of the text field
# $default -> Optional default value of the field if not
# already defined.
# $size -> Optional width of field in characaters.
# $maxlength -> Optional maximum number of characters.
# Returns:
# A string containing a field
#
sub textfield {
my($self,@p) = self_or_default(@_);
$self->_textfield('text',@p);
}
#### Method: filefield
# Parameters:
# $name -> Name of the file upload field
# $size -> Optional width of field in characaters.
# $maxlength -> Optional maximum number of characters.
# Returns:
# A string containing a field
#
sub filefield {
my($self,@p) = self_or_default(@_);
$self->_textfield('file',@p);
}
#### Method: password
# Create a "secret password" entry field
# Parameters:
# $name -> Name of the field
# $default -> Optional default value of the field if not
# already defined.
# $size -> Optional width of field in characters.
# $maxlength -> Optional maximum characters that can be entered.
# Returns:
# A string containing a field
#
sub password_field {
my ($self,@p) = self_or_default(@_);
$self->_textfield('password',@p);
}
#### Method: textarea
# Parameters:
# $name -> Name of the text field
# $default -> Optional default value of the field if not
# already defined.
# $rows -> Optional number of rows in text area
# $columns -> Optional number of columns in text area
# Returns:
# A string containing a tag
#
sub textarea {
my($self,@p) = self_or_default(@_);
my($name,$default,$rows,$cols,$override,$tabindex,@other) =
rearrange([NAME,[DEFAULT,VALUE],ROWS,[COLS,COLUMNS],[OVERRIDE,FORCE],TABINDEX],@p);
my($current)= $override ? $default :
(defined($self->param($name)) ? $self->param($name) : $default);
$name = defined($name) ? $self->_maybe_escapeHTML($name) : '';
$current = defined($current) ? $self->_maybe_escapeHTML($current) : '';
my($r) = $rows ? qq/ rows="$rows"/ : '';
my($c) = $cols ? qq/ cols="$cols"/ : '';
my($other) = @other ? " @other" : '';
$tabindex = $self->element_tab($tabindex);
return qq{};
}
#### Method: button
# Create a javascript button.
# Parameters:
# $name -> (optional) Name for the button. (-name)
# $value -> (optional) Value of the button when selected (and visible name) (-value)
# $onclick -> (optional) Text of the JavaScript to run when the button is
# clicked.
# Returns:
# A string containing a tag
####
sub button {
my($self,@p) = self_or_default(@_);
my($label,$value,$script,$tabindex,@other) = rearrange([NAME,[VALUE,LABEL],
[ONCLICK,SCRIPT],TABINDEX],@p);
$label=$self->_maybe_escapeHTML($label);
$value=$self->_maybe_escapeHTML($value,1);
$script=$self->_maybe_escapeHTML($script);
$script ||= '';
my($name) = '';
$name = qq/ name="$label"/ if $label;
$value = $value || $label;
my($val) = '';
$val = qq/ value="$value"/ if $value;
$script = qq/ onclick="$script"/ if $script;
my($other) = @other ? " @other" : '';
$tabindex = $self->element_tab($tabindex);
return $XHTML ? qq()
: qq();
}
#### Method: submit
# Create a "submit query" button.
# Parameters:
# $name -> (optional) Name for the button.
# $value -> (optional) Value of the button when selected (also doubles as label).
# $label -> (optional) Label printed on the button(also doubles as the value).
# Returns:
# A string containing a tag
####
sub submit {
my($self,@p) = self_or_default(@_);
my($label,$value,$tabindex,@other) = rearrange([NAME,[VALUE,LABEL],TABINDEX],@p);
$label=$self->_maybe_escapeHTML($label);
$value=$self->_maybe_escapeHTML($value,1);
my $name = $NOSTICKY ? '' : 'name=".submit" ';
$name = qq/name="$label" / if defined($label);
$value = defined($value) ? $value : $label;
my $val = '';
$val = qq/value="$value" / if defined($value);
$tabindex = $self->element_tab($tabindex);
my($other) = @other ? "@other " : '';
return $XHTML ? qq()
: qq();
}
#### Method: reset
# Create a "reset" button.
# Parameters:
# $name -> (optional) Name for the button.
# Returns:
# A string containing a tag
####
sub reset {
my($self,@p) = self_or_default(@_);
my($label,$value,$tabindex,@other) = rearrange(['NAME',['VALUE','LABEL'],TABINDEX],@p);
$label=$self->_maybe_escapeHTML($label);
$value=$self->_maybe_escapeHTML($value,1);
my ($name) = ' name=".reset"';
$name = qq/ name="$label"/ if defined($label);
$value = defined($value) ? $value : $label;
my($val) = '';
$val = qq/ value="$value"/ if defined($value);
my($other) = @other ? " @other" : '';
$tabindex = $self->element_tab($tabindex);
return $XHTML ? qq()
: qq();
}
#### Method: defaults
# Create a "defaults" button.
# Parameters:
# $name -> (optional) Name for the button.
# Returns:
# A string containing a tag
#
# Note: this button has a special meaning to the initialization script,
# and tells it to ERASE the current query string so that your defaults
# are used again!
####
sub defaults {
my($self,@p) = self_or_default(@_);
my($label,$tabindex,@other) = rearrange([[NAME,VALUE],TABINDEX],@p);
$label=$self->_maybe_escapeHTML($label,1);
$label = $label || "Defaults";
my($value) = qq/ value="$label"/;
my($other) = @other ? " @other" : '';
$tabindex = $self->element_tab($tabindex);
return $XHTML ? qq()
: qq//;
}
#### Method: comment
# Create an HTML
# Parameters: a string
sub comment {
my($self,@p) = self_or_CGI(@_);
return "";
}
#### Method: checkbox
# Create a checkbox that is not logically linked to any others.
# The field value is "on" when the button is checked.
# Parameters:
# $name -> Name of the checkbox
# $checked -> (optional) turned on by default if true
# $value -> (optional) value of the checkbox, 'on' by default
# $label -> (optional) a user-readable label printed next to the box.
# Otherwise the checkbox name is used.
# Returns:
# A string containing a field
####
sub checkbox {
my($self,@p) = self_or_default(@_);
my($name,$checked,$value,$label,$labelattributes,$override,$tabindex,@other) =
rearrange([NAME,[CHECKED,SELECTED,ON],VALUE,LABEL,LABELATTRIBUTES,
[OVERRIDE,FORCE],TABINDEX],@p);
$value = defined $value ? $value : 'on';
if (!$override && ($self->{'.fieldnames'}->{$name} ||
defined $self->param($name))) {
$checked = grep($_ eq $value,$self->param($name)) ? $self->_checked(1) : '';
} else {
$checked = $self->_checked($checked);
}
my($the_label) = defined $label ? $label : $name;
$name = $self->_maybe_escapeHTML($name);
$value = $self->_maybe_escapeHTML($value,1);
$the_label = $self->_maybe_escapeHTML($the_label);
my($other) = @other ? "@other " : '';
$tabindex = $self->element_tab($tabindex);
$self->register_parameter($name);
return $XHTML ? CGI::label($labelattributes,
qq{$the_label})
: qq{$the_label};
}
# Escape HTML
sub escapeHTML {
require HTML::Entities;
# hack to work around earlier hacks
push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
my ($self,$toencode,$newlinestoo) = CGI::self_or_default(@_);
return undef unless defined($toencode);
my $encode_entities = $ENCODE_ENTITIES;
$encode_entities .= "\012\015" if ( $encode_entities && $newlinestoo );
return HTML::Entities::encode_entities($toencode,$encode_entities);
}
# unescape HTML -- used internally
sub unescapeHTML {
require HTML::Entities;
# hack to work around earlier hacks
push @_,$_[0] if @_==1 && $_[0] eq 'CGI';
my ($self,$string) = CGI::self_or_default(@_);
return undef unless defined($string);
return HTML::Entities::decode_entities($string);
}
# Internal procedure - don't use
sub _tableize {
my($rows,$columns,$rowheaders,$colheaders,@elements) = @_;
my @rowheaders = $rowheaders ? @$rowheaders : ();
my @colheaders = $colheaders ? @$colheaders : ();
my($result);
if (defined($columns)) {
$rows = int(0.99 + @elements/$columns) unless defined($rows);
}
if (defined($rows)) {
$columns = int(0.99 + @elements/$rows) unless defined($columns);
}
# rearrange into a pretty table
$result = "
";
my($row,$column);
unshift(@colheaders,'') if @colheaders && @rowheaders;
$result .= "
" if @colheaders;
for (@colheaders) {
$result .= "
$_
";
}
for ($row=0;$row<$rows;$row++) {
$result .= "
";
$result .= "
$rowheaders[$row]
" if @rowheaders;
for ($column=0;$column<$columns;$column++) {
$result .= "
" . $elements[$column*$rows + $row] . "
"
if defined($elements[$column*$rows + $row]);
}
$result .= "
";
}
$result .= "
";
return $result;
}
#### Method: radio_group
# Create a list of logically-linked radio buttons.
# Parameters:
# $name -> Common name for all the buttons.
# $values -> A pointer to a regular array containing the
# values for each button in the group.
# $default -> (optional) Value of the button to turn on by default. Pass '-'
# to turn _nothing_ on.
# $linebreak -> (optional) Set to true to place linebreaks
# between the buttons.
# $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:
# An ARRAY containing a series of fields
####
sub radio_group {
my($self,@p) = self_or_default(@_);
$self->_box_group('radio',@p);
}
#### Method: checkbox_group
# Create a list of logically-linked checkboxes.
# Parameters:
# $name -> Common name for all the check boxes
# $values -> A pointer to a regular array containing the
# values for each checkbox in the group.
# $defaults -> (optional)
# 1. If a pointer to a regular array of checkbox values,
# then this will be used to decide which
# checkboxes to turn on by default.
# 2. If a scalar, will be assumed to hold the
# value of a single checkbox in the group to turn on.
# $linebreak -> (optional) Set to true to place linebreaks
# between the buttons.
# $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:
# An ARRAY containing a series of fields
####
sub checkbox_group {
my($self,@p) = self_or_default(@_);
$self->_box_group('checkbox',@p);
}
sub _box_group {
my $self = shift;
my $box_type = shift;
my($name,$values,$defaults,$linebreak,$labels,$labelattributes,
$attributes,$rows,$columns,$rowheaders,$colheaders,
$override,$nolabels,$tabindex,$disabled,@other) =
rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LINEBREAK,LABELS,LABELATTRIBUTES,
ATTRIBUTES,ROWS,[COLUMNS,COLS],[ROWHEADERS,ROWHEADER],[COLHEADERS,COLHEADER],
[OVERRIDE,FORCE],NOLABELS,TABINDEX,DISABLED
],@_);
my($result,$checked,@elements,@values);
@values = $self->_set_values_and_labels($values,\$labels,$name);
my %checked = $self->previous_or_default($name,$defaults,$override);
# If no check array is specified, check the first by default
$checked{$values[0]}++ if $box_type eq 'radio' && !%checked;
$name=$self->_maybe_escapeHTML($name);
my %tabs = ();
if ($TABINDEX && $tabindex) {
if (!ref $tabindex) {
$self->element_tab($tabindex);
} elsif (ref $tabindex eq 'ARRAY') {
%tabs = map {$_=>$self->element_tab} @$tabindex;
} elsif (ref $tabindex eq 'HASH') {
%tabs = %$tabindex;
}
}
%tabs = map {$_=>$self->element_tab} @values unless %tabs;
my $other = @other ? "@other " : '';
my $radio_checked;
# for disabling groups of radio/checkbox buttons
my %disabled;
for (@{$disabled}) {
$disabled{$_}=1;
}
for (@values) {
my $disable="";
if ($disabled{$_}) {
$disable="disabled='1'";
}
my $checkit = $self->_checked($box_type eq 'radio' ? ($checked{$_} && !$radio_checked++)
: $checked{$_});
my($break);
if ($linebreak) {
$break = $XHTML ? " " : " ";
}
else {
$break = '';
}
my($label)='';
unless (defined($nolabels) && $nolabels) {
$label = $_;
$label = $labels->{$_} if defined($labels) && defined($labels->{$_});
$label = $self->_maybe_escapeHTML($label,1);
$label = "$label" if $disabled{$_};
}
my $attribs = $self->_set_attributes($_, $attributes);
my $tab = $tabs{$_};
$_=$self->_maybe_escapeHTML($_);
if ($XHTML) {
push @elements,
CGI::label($labelattributes,
qq($label)).${break};
} else {
push(@elements,qq/${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) {
%selected = map {$_=>1} ref($default) eq 'ARRAY'
? @$default
: $default;
}
$name=$self->_maybe_escapeHTML($name);
# RT #30057 - ignore -multiple, if you need this
# then use scrolling_list
@other = grep { $_ !~ /^multiple=/i } @other;
my($other) = @other ? " @other" : '';
my(@values);
@values = $self->_set_values_and_labels($values,\$labels,$name);
$tabindex = $self->element_tab($tabindex);
$name = q{} if ! defined $name;
$result = qq/";
return $result;
}
#### Method: optgroup
# Create a optgroup.
# Parameters:
# $name -> Label for the group
# $values -> A pointer to a regular array containing the
# values for each option line in the group.
# $labels -> (optional)
# A pointer to a hash of labels to print next to each item
# in the form $label{'value'}="Long explanatory label".
# Otherwise the provided values are used as the labels.
# $labeled -> (optional)
# A true value indicates the value should be used as the label attribute
# in the option elements.
# The label attribute specifies the option label presented to the user.
# This defaults to the content of the