Straight from the guts of CGI.pm, where you should've had at least one visit ;)
#### 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 an associative array of labels to print nex
+t 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 <INPUT TYPE="radio"> fields
####
'radio_group' => <<'END_OF_FUNC',
sub radio_group {
my($self,@p) = self_or_default(@_);
my($name,$values,$default,$linebreak,$labels,
$rows,$columns,$rowheaders,$colheaders,$override,$nolabels,@oth
+er) =
rearrange([NAME,[VALUES,VALUE],DEFAULT,LINEBREAK,LABELS,
ROWS,[COLUMNS,COLS],
ROWHEADERS,COLHEADERS,
[OVERRIDE,FORCE],NOLABELS],@p);
my($result,$checked);
if (!$override && defined($self->param($name))) {
$checked = $self->param($name);
} else {
$checked = $default;
}
my(@elements,@values);
@values = $self->_set_values_and_labels($values,\$labels,$name);
# If no check array is specified, check the first by default
$checked = $values[0] unless defined($checked) && $checked ne '';
$name=$self->escapeHTML($name);
my($other) = @other ? " @other" : '';
foreach (@values) {
my($checkit) = $checked eq $_ ? qq/ checked="checked"/ : '';
my($break);
if ($linebreak) {
$break = $XHTML ? "<br />" : "<br>";
}
else {
$break = '';
}
my($label)='';
unless (defined($nolabels) && $nolabels) {
$label = $_;
$label = $labels->{$_} if defined($labels) && defined($labels-
+>{$_});
$label = $self->escapeHTML($label,1);
}
$_=$self->escapeHTML($_);
push(@elements,$XHTML ? qq(<input type="radio" name="$name" value=
+"$_"$checkit$other />${label}${break})
: qq/<input type="radio" name="$name" va
+lue="$_"$checkit$other>${label}${break}/);
}
$self->register_parameter($name);
return wantarray ? @elements : join(' ',@elements)
unless defined($columns) || defined($rows);
return _tableize($rows,$columns,$rowheaders,$colheaders,@elements)
+;
}
END_OF_FUNC
perl -MData::Dumper -MCGI=:all -e"print Dumper radio_group('IamGroup',
+[qw/one othe
r/],'one','linebreaks');"
perl -MCGI=all -e"print textfield('other')"
Now what I'm wondering is how is it that you didn't happen to stumble accross the CGI documentation, or even its guts?
P.S. -- here's a few *secret* links, don't tell nobody (
CGI,
How to RTFM,
http://ovid.perlmonk.org,
http://stein.cshl.org/,
perlsec)
update:
Whaza?
1) No the CGI documentation does not explicitly state how you can do what you want (you're doing some odd things, and it'd be crazy for the documentation to reflect that).
2) Nooooo, If you don't know how to use certain functions, or they're not documented to your satisfaction, just crack open CGI.pm (and yeah, you could borrow, but that wasn't my point)
3) Didn't mean to imply you should modify CGI.pm
Yes, you missed my point completely (I guess I should've been more explicit, kinda like jeffa up there).
I just wanted to point out to you, radio_group (which returns a list) and textfield, two CGI.pm functions, which *you* can use to solve your problem. You have to use your imagination as to how to do it (i ain't writing code like jeffa, ain't got time)
Hopefully that clarifies it (if not, update your reply).
Look ma', I'm on CPAN.
** The Third rule of perl club is a statement of fact: pod is sexy. |