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

I am trying to learn CGI.pm and am having a bit of trouble with getting the values out of radio buttons.
I think the problem lies in the fact that I dont understand the way radio_button stores its selected value.
radio_group(-name=>['add_remove'], -values=>['Add','Remove'], -default=>'Add', -labels=>\%labels),p,
and when I try to print back whats in the add_remove value I get nothing
"Rule: ",em(param('add_remove')),p,
I thought that the add_remove instance of radio_buttone would just contain whatever value is checked by default or if it is changed. Can anyone explain what is going on? Or can post an example of a working radio button in CGI.pm I can prolly figure it out.
#!/usr/bin/perl -w use CGI qw/:standard/; print header, start_html('Service Request Form'), h1('Service Request Form'), start_form, "Name:<br>",textfield('name'),p, "Phone:<br>",textfield('phone'),p, "Date:<br>",textfield('date'),p, "Email:<br>",textfield('email'),p, "Add or Remove this rule", "<br>", radio_group(-name=>['add_remove'], -values=>['Add','Remove'], -default=>'Add', -labels=>\%labels),p, "Source:<br>",textfield('source'),p, "Destination:<br>",textfield('destination'),p, "Service:<br>",textfield('service'),p, "What do you want to happen to this traffic?", "<br>", radio_group(-name=>['action'], -values=>['Accept','Reject'], -default=>'Accept', -labels=>\%labels),p, "Please describe what you are trying to accomplish:<br>", textarea(-name=>'description', -rows=>10, -columns=>50),p, submit, end_form, hr,"\n"; if (param) { print "Name ",em(param('name')),p, "Phone Number: ",em(param('phone')),p, "Date: ",em(param('date')),p, "Email: ",em(param('email')),p, "Rule: ",em(param('add_remove')),p, "Source: ",em(param('source')),p, "Destination: ",em(param('destination')),p, "Service: ",em(param('service')),p, "Action: ",em(param('action')),p, "Description: ",em(param('description')),p, } print end_html;

Replies are listed 'Best First'.
Re: Please help with my CGI.pm misinterpritation
by fruiture (Curate) on Aug 09, 2002 at 16:09 UTC

    That's, luckily, easy: The -name parameter for radio_group expects a string. So your arrayref will be stringified, but that name is not usefull. And: You haven't defined %labels anywhere!

    See the documentation for further details.

    --
    http://fruiture.de