Having avoided CGI.pm for a long while, as I like my coding to look just right, I'm just getting to grips with its state-flow.
But these have me stumped (well a dodgy LBW call): 1) Basically I have n + (5 or 6) texstfields to fill, initially from a file which works fine. Then the user makes changes and submits changes to the same script (don't want to use 2 scripts ideally), which identifies that it has been called via form (POST etc., "if(param())" ). Then it's job is to eliminate empty fields, and display n + (5 or 6) fields with the user data submitted. (see PROBLEM SECTION) The PROBLEM is that the text/input fields are given the default values from what the user entered before submitting, and for some reason my processing doesn't overwrite these defaults. 2) Any info on getting control over Tables while using CGI.pm also greatfully received. As you can see I would like to be consistent, but due to time constarints have had to sacrafice my honor for progress. Gave up looking for answers after reading several posts on this subject on this list and others. My current conclusion is that putting loops and such like inside Tables can't be achieved using CGI.pm as-it-is. (Which seems strange to me as tables are quite often the result of a loop.) I have left the '*table' in 'use CGI' as a reminder of my failure. Anyho, heres the essence of my code, Thanks for your time :) Tom. #!/usr/local/bin/perl -w use CGI qw/:standard *table/; ################# # Define Variables $basedir = "/home/root/path/comment/admin/"; $baseurl = "http://path.to.this.script/"; $cgi_url = "http://path.to.this.script/"; $datafile = "comments.txt"; $title = "Comment Admin"; $subtitle = "Flying Comments"; ################ # Configure Options @add_comments = (6, 5); # (even, odd) additional blank comment textfields. $it = new CGI; # init new CGI object. ####### if($it->param()) { # Params passed via POST for ($p=$n=1,$cc=0; $p <= $it->param('oldfcount'); $p++,$n++) { $comments{"comment$n"} = $it->param("comment$p"); ($comments{"comment$n"} ne "") ? $cc++ : $n--; } # $fcount = $cc + $add_comments[($cc % 2)]; for ($i=($cc+1); $i<=$fcount; $i++) { $comment{"comments$i"} = ""; } } else { # Else on first call, get data from file &get_comments; } print $it->header, $it->start_html(-title=>$title, -BGCOLOR=>'#000000', -LINK=>'#999999', -VLINK=>'#999999', -ALINK=>'#0000FF', -TEXT=>'#FFFFFF'),"\n\n", $it->br,"\n", $it->b($it->font({-face=>'Arial',-size=>'2'}, "$title")), $it->br,"\n", $it->b($it->font({-face=>'Arial',-size=>'1'}, "$subtitle")), $it->br,"\n", $it->br,"\n", $it->start_form(-name=>'formComments',-action=>"$cgi_url",-method=>'POST'), $it->hidden(-name=>'oldfcount',-default=>"$fcount"); print "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">\n "; for($i=1; $i<=$fcount; $i+=2) { $keyl = "comment$i"; $keyr = "comment". ($i+1); print "<TR>\n", " <TD ALIGN=\"left\">\n", " ", $it->br, "\n", " ", $it->font({-face=>'Arial',-size=>'2'}, "comment $i"), $it->br, "\n", " ", $it->textfield(-name=>"$keyl", -size=>'37', -maxlength=>'35', -default=>"$comments{$keyl}"), "\n", " <TD ALIGN=\"left\">\n", " ", $it->br,"\n", " ", $it->font({-face=>'Arial',-size=>'2'}, "comment ".($i+1)), $it->br ,"\n", " ", $it->textfield(-name=>"$keyr", -size=>'37', -maxlength=>'35', -default=>"$comments{$keyr}"), "\n", " </TD>\n", " </TR>"; } print "<TR>\n", " <TD ALIGN=\"center\">\n", " ", $it->submit(-name=>'submit',-value=>' Publish ') ,"</TD>\n", " <TD ALIGN=\"center\">\n", " ", $it->reset(-value=>' Undo ') ,"</TD>\n", " </TR>\n", ### DEBUG ### "<TR>\n", " <TD ALIGN=\"left\">\n", " fcount = $fcount<BR>\n", " p = $p<BR>\n", " cc = $cc<BR>\n", " oldfcount = ". $it->param('oldfcount') ."<BR>\n", " fcount (mod 2) = ".($fcount % 2)."<BR>\n", " oddOReven = $oddoreven<BR>\n", " add_comments[oddOReven] = ".$add_comments[$oddoreven]."<BR>\n", " </TR><TR>\n", " <TD ALIGN=\"left\">\n"; foreach $key (keys %comments) { print " $key = $comments{$key}<BR>\n"; } print " </TD>\n", " </TR>\n", ### END DEBUG ### "\n</TABLE>\n"; print $it->end_form,"\n", $it->end_html; exit; ############################ # Get/Set Subroutines sub get_comments { #... } sub set_comments { #... } -- Personalised email by http://another.com
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
