in reply to Re: CGI.PM automaticly reset form to Defaults
in thread CGI.PM automaticly reset form to Defaults

No i have made a script that searches /var/www/html/bestellingen/ingezet/ for files
it displays the files and then the user has three options
do nothing (niets)
place the file in /var/www/html/bestellingen/postvak_uit (verzenden)
or place the file in /var/www/html/bestellingen/nakijken (nakijkeną
The script works fine but when i push the submit (verwerken) button the screen needs to refresh and that does not work i have a set to defaults button when i push it everything is ok
Here is my code it is probably the ugliest code you ever seen but i'm not a programmer and new to perl
#!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard :html3/; use File::Copy; $waarbestel='/var/www/html/'; $path_to_files='/var/www/html/bestellingen/ingezet'; $q = new CGI; &zoekfiles ($path_to_files); sub zoekfiles { $path1= shift @_; #het path waar de files staan my %berichten = &listfiles ($path1); @hoofdingen= ('Bon','Fax','Mail.','Leverancier','Lev. nr.','Actie'); @rijen = th(\@hoofdingen); foreach my $berichtbestelbonnr (keys %berichten) { for my $berichtrol (keys %{$berichten{$berichtbestelbonnr}} ) { #print "$berichten{$berichtbestelbonnr}{$berichtrol} " ; $fax1 = "$berichten{$berichtbestelbonnr}{$berichtrol} " if ($beric +htrol eq 'fax'); $mail1 = "$berichten{$berichtbestelbonnr}{$berichtrol} " if ($beri +chtrol eq 'mail'); $lev1 = "$berichten{$berichtbestelbonnr}{$berichtrol} " if ($beri +chtrol eq 'leverancier'); $levnr1= "$berichten{$berichtbestelbonnr}{$berichtrol} " if ($beri +chtrol eq 'leveranciersnummer'); $link1= "$berichten{$berichtbestelbonnr}{$berichtrol} " if ($beric +htrol eq 'link'); } $verwijzing= a({-href=>"http://localhost/$link1", -style => 'color: blue;' },"$berichtbestelbonnr"); $actie=popup_menu(-name=>"$berichtbestelbonnr", -values=>['niets','verzenden','nakijken'], -default=> 'niets'); push (@rijen,td([$verwijzing,$fax1,$mail1,$lev1,$levnr1,$actie])); } print $q->header; print $q->start_html (-title =>'Bestellingen die ingezet werden', -BGCOLOR=>'cyan'), $q->a({-href=>"t12.pl"},"Ingezet"), " - ", $q->a({-href=>"t1.pl"},"Postvak-Uit"), " - ", $q->a({-href=>"t1.pl"},"Verzonden"), " - ", $q->a({-href=>"t1.pl"},"Bevestigd"), " - ", $q->a({-href=>"t1.pl"},"Nakijken"), $q->p, $q->h1({-style=>'Color: blue;'},'Bestellingen die ingezet werd +en'), $q->p, $q->start_form; print $q->table({-border=>undef,-width=>'95%'}, Tr(\@rijen) ), $q->submit(-name=>'Doorsturen', -value=>'Verwerken'), $q->defaults('Defaults'), $q->end_form, $q->hr; print $q->end_html; $verwerken = param('Doorsturen'); if ($verwerken =~ 'Verwerken') { foreach my $berichtbestelbonnr (keys %berichten) { $popup_menu_waarde=$q->param("$berichtbestelbonnr"); $file_to_proces=$berichten{$berichtbestelbonnr}{'link'}; $file_to_proces=~s%bestellingen/ingezet/%%; if ($popup_menu_waarde eq 'verzenden') { #print "$path_to_files$file_to_proces===>/var/www/html/bestelling +en/postvak-uit/$file_to_proces"; move("$path_to_files/$file_to_proces", "/var/www/html/bestellinge +n/postvak-uit/$file_to_proces"); }elsif ($popup_menu_waarde eq 'nakijken') { move("$path_to_files/$file_to_proces", "/var/www/html/bestellinge +n/nakijken/$file_to_proces"); } #print "Verwerkt"; } print "Verwerkt"; # here in need to set the screen to defaults or refresh the screen } } sub listfiles { #haal de directorY $dirtolist= shift @_; $_=$dirtolist; s%/var/www/html/%%; $reldir=$_; #print "\n dir delete $dirtoempty\n"; $extension_to_list= "pdf"; opendir (DIR,"$dirtolist"); @files = grep(/.*$extension_to_list$/, readdir (DIR)); foreach (@files) { my $filename=$_; $linktofile="$reldir/$filename"; if (m%---\d+.pdf%g) { #bestelbonnummer $_= $& ; s%.pdf%%; s%---%%; $bestelbonnummer=$_; #print "bestel: $_\n"; $_=$filename; s%---$bestelbonnummer.%.%; $filename= $_; } if (m%---\d+.pdf%) { #leveranciersnummer $_= $& ; s%.pdf%%; s%---%%; $leveranciersnummer=$_; #print "levnr: $_\n"; $_=$filename; s%---$leveranciersnummer.%.%; $filename= $_; } if (m%---\w+.pdf%) { #leverancier $_= $& ; s%.pdf%%; s%---%%; $leverancier=$_; #print "lev: $_\n"; $_=$filename; s%---$leverancier.%.%; $filename= $_; } if (m%---\d+.pdf%) { #fax $_= $& ; s%.pdf%%; s%---%%; $fax=$_; #print "fax: $_\n"; $_=$filename; s%---$fax.%.%; $filename= $_; } if (m%\w+@\w+.\w+.pdf%) { #mail $_= $& ; s%.pdf%%; s%---%%; $mail=$_; #print "mail: $_\n"; $_=$filename; s%---$mail.%.%; $filename= $_; } $bestelling {$bestelbonnummer} = { 'leveranciersnummer' => $leveranciersnummer, 'leverancier' => $leverancier, 'fax' => $fax, 'mail' => $mail, 'link' => $linktofile }; } #print @files; closedir (DIR); return (%bestelling); }

Replies are listed 'Best First'.
Re^3: CGI.PM automaticly reset form to Defaults
by almut (Canon) on Jan 14, 2007 at 18:02 UTC

    (Note: I have that sneaking suspicion it was you, harryC, who downvoted me (for trying to help), so you'll understand that my follow-up response is somewhat less verbose than it would be otherwise...   UPDATE: it turned out my suspicion was wrong. I'm sorry for that!)

    So, yes, I do think you more or less have the scenario I decribed: you do not specify an "action" URI when you call start_form, so CGI.pm will submit to itself (the default), i.e. the URI that generated the page/form...   and thus put the parameters received as initial values into the subsequent form on the response page (this is default magic of CGI.pm).

    What you want is: extract the parameters you need (like $verwerken = param('Doorsturen'), etc.), then call $q->delete_all. Both needs to be done before you output the form with $q->start_form .

    Alternatively, in particular if you don't really want the form at all on the response page, specify -action => $some_other_URI as argument to start_form(), and generate the response page via some other CGI script...

      Sorry
      I don't understand the part of downvoted
      I did not downvote anyone or it must be by accident
      I was not aware of any voting system , I guess i need to read about it
      I noticed above my msg it says reputation 1 what does that mean ?
      However thank you again for your reply I will certain test it out rgds
        Hi harryC:

        "I guess i need to read about it I noticed above my msg it says reputation 1 what does that mean ?"

        Check out Voting/Experience System and the PerlMonks FAQ to familiarise yourself with this concept.

        Thanks.

        Martin
        I did not downvote anyone or it must be by accident

        In that case, I apologise!   Hope you'll get your script working.