S
Steve (another one)
Dear all
I have a script which writes an html form using CGI.pm. It is very
convenient to have multiple fields with the same name from which I can
extract values by treating them as an array. The problem is that on
subsequent submissions of the form, all values default to the first. The
only way I can reset them to the value that they previously had is to
use javascript to assign their values to those found in the parameters
array. This is very ugly, there must be a better way, does anyone have
any suggestions ?
Thanks
Below is a minimal example, enter different values in the boxes and
submit - values are sucessfully recovered but defaults revert to the
value on box 0.
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = new CGI;
my @param_names = $q->param;
my %myparams;
foreach (@param_names){
(@{$myparams{$_}}=$q->param($_))=~ s/[^a..z,A..Z]/_/g;
}
print $q->header(-type =>"text/html", -expires=>"-1d"),
$q->start_html(),
$q->start_form(-method=>'post');
for my $cnt (0..5) {print "box $cnt ",
$q->textfield(-name=>'text'),'<br>'}
print '<br><br>',
$q->submit(-name=>'submitbutton', -value=>'Submit'),
$q->endform;
foreach (@{$myparams{text}}) {print "<br>$_\n"}
print $q->end_html;
I have a script which writes an html form using CGI.pm. It is very
convenient to have multiple fields with the same name from which I can
extract values by treating them as an array. The problem is that on
subsequent submissions of the form, all values default to the first. The
only way I can reset them to the value that they previously had is to
use javascript to assign their values to those found in the parameters
array. This is very ugly, there must be a better way, does anyone have
any suggestions ?
Thanks
Below is a minimal example, enter different values in the boxes and
submit - values are sucessfully recovered but defaults revert to the
value on box 0.
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $q = new CGI;
my @param_names = $q->param;
my %myparams;
foreach (@param_names){
(@{$myparams{$_}}=$q->param($_))=~ s/[^a..z,A..Z]/_/g;
}
print $q->header(-type =>"text/html", -expires=>"-1d"),
$q->start_html(),
$q->start_form(-method=>'post');
for my $cnt (0..5) {print "box $cnt ",
$q->textfield(-name=>'text'),'<br>'}
print '<br><br>',
$q->submit(-name=>'submitbutton', -value=>'Submit'),
$q->endform;
foreach (@{$myparams{text}}) {print "<br>$_\n"}
print $q->end_html;