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

I am a beginner in perl. I am getting problem while maintaining a state information of web form. Below is the partial code that i am using in my script using CGI module.
if(param('listName')){ $listvalue = param('listName'); $current = "/Desktop/$listvalue"; find (\&processFiles, $current); &processData(); }else{ print "Content-type: text/html\n\n"; if(param('txtName')){ @txtvalues = param('txtName'); }else{ @txtvalues = param('tName'); print @txtvalues;} %data = param('hashdata'); print @txtvalues; &manageStateProcess(); } sub processData() { while ((my $keys, my $values) = each(%data)){ $comment=""; if($values =~m/(.*?\s)\ *(\#.*)/){ $values="$1";$comment="$2";} if ($keys =~m/^.*File.*$/){ #$check{$keys}=$values; push(@checkbox_rows, td([table(font({-color=>"blue"},$keys +)),table(checkbox(-name=>"",-value=>$values,-size=>15)),table($commen +t)])); }else{ push(@textfield_rows, td([table(font({-color=>"blue"},$key +s)),table(textfield(-name=>'txtName',-value=>$values,-size=>25)),tabl +e($comment)])); } } } sub manageStateProcess() { my $i=0; my %hashtextField; while ((my $keys, my $values) = each(%data)){ $comment=""; if($values =~m/(.*?\s)\ *(\#.*)/){ $values="$1";$comment="$2";} if ($keys =~m/^.*File.*$/){ push(@checkbox_rows, td([table(font({-color=>"blue"},$keys +)),table(checkbox(-name=>"", -value=>$values,-size=>15)),table($comme +nt)])); }else{ my $values = $txtvalues[$i]; print "<b>$values<b>"; $i++; push(@textfield_rows, td([table(font({-color=>"blue"},$key +s)),table(textfield(-name=>$keys,-value=>$values,-size=>25)),table($c +omment)])); #hidden(-name=>'tdata', -values=>[@text]); } } } print header; print start_html('N1 Grid'); print h4({-align=>'center'},'N1 Grid'); print hr; my $a="Test"; if ($a){ print h1({-align=>'center'},$a); } print p{-align=>'RIGHT'},a({-href=>"parsecfg.pl"},"Go to home page" +), start_form(-method=>"POST", -action=> 'cfgdata13.pl'), table({-align=>'CENTER',-valign=>'TOP'},Tr(\@checkbox_rows)), table({-align=>'CENTER',-valign=>'TOP'},Tr(\@textfield_rows)), hidden(-name=>'hashdata', -values=>[%data]), p{-align=>'CENTER'}, submit, end_form; print end_html;
Here is what I want exactly. Every time when I submit the form, it should maintain the previous record. In my form, I am creating a numbers of textfield and I want to maintain each value with its previous record while submitting a form. Is there a way can I access a list of textfield value by using array like @textvalues=param($keys); or is there any other way to pass textfield name for each value in a loop. currently I am using "push(@textfield_rows, td(table(font({-color=>"blue"},$keys)),table(textfield(-name=>$keys,-value=>$values,-size=>25)),table($comment)));" but, I cannot access textfield value while declare as textfield(-name=>$keys,,-value=>$values). Help needed senior monks, Thanks in advance.

Replies are listed 'Best First'.
Re: Maintain State Information
by Utilitarian (Vicar) on Aug 12, 2009 at 20:16 UTC
    As far as I remember in CGI inputs -values takes an array ref if you want to have multiple values. Order is preserved.
    As an aside you should always run a CGI script with -T, particularly if you are letting params near the filesystem.