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 |