in reply to Creating HTML radio button group with text field

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.

Replies are listed 'Best First'.
Re: (podmaster) Re: Creating HTML radio button group with text field
by impossiblerobot (Deacon) on May 05, 2002 at 04:16 UTC

    I'm not sure I understand the point of your post. Are you saying that:

    • the CGI.pm documentation specifically describes how to do what I asked? If so, I need a better hint as to where. I had already read the links you referenced, as well as Lincoln Stein's book, but I couldn't find the answer to how to attach a text box to a radio button using CGI.pm. That's why I posted. :-)
      (I already know how to generate a radio group or a textbox with CGI.pm, and I could probably hack something together, but I don't think it would be very pretty.)

    • there are some undocumented features hidden in the CGI.pm code that I could exploit to meet my requirements? If so, I didn't see them.

    • rather than roll my own, I should modify the code from CGI.pm to do what I want? Since my code doesn't need to fit into Stein's fairly complex environment and doesn't need to be that generic, wouldn't that be kind of silly?

    Or it may be that I missed your point completely. I'm not trying to be ungrateful; I just need some clarification. :-(

    Thanks.
    Impossible Robot