The most likely culprit if your problem is the end_form function as demonstrated below.

I created the following cgi script to test your issue

#!/usr/bin/perl -wT use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use warnings; my $q = CGI->new; print $q->header(); print <<"END_HTML"; <html> <body> <form method="post"> END_HTML foreach my $f (qw(foo bar baz)) { print "<p>$f</p>\n"; print $q->radio_group( -name => $f, -values => [qw(c r t s)], -default => '-', ) . "\n"; } print $q->submit(-name => 'submit', -value => 'save') . "\n"; print <<"END_HTML"; </form> </body> </html> END_HTML 1; __END__

This appears to work as you desire. You can hit submit multiple times, and it will only autofill the radio buttons that were previously selected by the user.

However, if I replace my hardcoded form tags with the cgi functions start_form and end_form, then your problem appears.

#!/usr/bin/perl -wT use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use warnings; my $q = CGI->new; print $q->header(); print <<"END_HTML"; <html> <body> END_HTML print $q->start_form() . "\n"; # <------ Changed code foreach my $f (qw(foo bar baz)) { print "<p>$f</p>\n"; print $q->radio_group( -name => $f, -values => [qw(c r t s)], -default => '-', ) . "\n"; } print $q->submit(-name => 'submit', -value => 'save') . "\n"; print $q->end_form() . "\n"; # <------ Changed code print <<"END_HTML"; </body> </html> END_HTML 1; __END__

I therefore suggest that you start your investigation there. At the very least you can hardcode your form tags and avoid the problem, but it appears the end_form function adds the following text that for some reason creates your issue.

<div><input type="hidden" name=".cgifields" value="bar" /><input type +="hidden" name=".cgifields" value="baz" /><input type="hidden" name=".cgifields +" value="f oo" /></div>
- Miller

In reply to Re: How to get unselected radio_group() items after submitting form by wind
in thread How to get unselected radio_group() items after submitting form by slugger415

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.