CGI.pm param data is "sticky" meaning that if you create a field name with the same name as the name of an existing param field the new field will automatically be populated with the "old" param value. (That's the default. CGI.pm provides an "override" option if you don't want that.)
Anyway, your problem is that you're generating a form field BEFORE fetching the param values from the previous invocation of the script. CGI.pm sees a "name" param and has no idea which item in the param('name') list goes in which field on the screen. So it puts the 0 index in both.
In cases like this you need to fetch the param data FIRST, and then set each form fields equal to the correct index of the resulting array, and call the override attribute at the same time. Like this:
#!/usr/bin/perl -w
use CGI qw/:standard/;
my @values;
if (param) {
@values = param('name');
}
print header, start_html, start_form;
print textfield(-name=>'name',
-default=>$values[0],
-override=>1);
print textfield(-name=>'name',
-default=>$values[1],
-override=>1);
print submit, end_form, print end_html;
Gary Blackburn
Trained Killer
Correction: Fixed a scoping problem. |