kosta has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,
I am wondering if there is a CGI.pm function to create a single radio button? I mean I would create somethign like :
$cgi->radio_button(-name => ... , -value => ..., -label => ....);
I will write it myself if there is no such thing but I would hate to do something not necessary

Replies are listed 'Best First'.
Re: CGI.pm single radio button
by jethro (Monsignor) on Mar 30, 2011 at 11:58 UTC

    You seem to be looking for radio_group()

    But usually radio buttons are used to select exactly one out of a few alternatives, which makes no sense if you only have one alternative. If you are looking for an on/off-selection, checkbox() is better. There is also a visual difference and you probably will (slightly) confuse users of your webpage if you use a single radio button for an on/off-selection.

      I have a few alternatives I just need to create them separately since the name and value are dynamically assigned from db
        You can always collect the data in an array so that you later can create the radio group together
Re: CGI.pm single radio button
by Corion (Patriarch) on Mar 30, 2011 at 11:32 UTC

    Have you looked at what the CGI documentation has to say about "radio"? How about creating a single-item group?

Re: CGI.pm single radio button
by Anonymous Monk on Mar 30, 2011 at 11:33 UTC
    $ perl -MCGI -le " print CGI->radio_group( qw! -name solo -values !, [ + 123 ] ) " <label><input type="radio" name="solo" value="123" checked="checked" / +>123</label>
      is there a way for me to have no labels for my radiobuttons? I mean I want to have a couple of radiobuttons in a matrix and have them be without any labels. I tried something in terms of -labels => '' or -labels => '' and nothing.. how do I make it without labels
        sure, don't use CGI for html generation :)
        $ perl -MCGI=-no_xhtml -le " print CGI->radio_group( qw! -name solo -v +alues !, [ 123 ] ) " <input type="radio" name="solo" value="123" checked >123