in reply to perl cgi - refresh question

One thing you could do would be to include an identity variable to activate a subroutine/script which updates the text file, without it it simply reads it:
my $check=param('check'); my $value=param('value'); if (($value) && ($check)) { #update text file here or go to sub routine } else { #show report }
Or something like that...

Update: The check variable would be included in the form submission, and the above code has been revised to reflect that. On discussion with zby this would not work if it is desirable to update the file via the URL - I have assumed it is not. If updates from the URL are required then zby's suggestion would allow this.

Replies are listed 'Best First'.
Re: Re: perl cgi - refresh question
by zby (Vicar) on Apr 15, 2003 at 12:25 UTC
    The problem is that when the page is refreshed than the identity variable will be resent.
      No, because the URL still stands:
      http://localhost/cgi-bin/sample_report.pl?value=xyz.

      the $check variable is used in the script to differentiate between viewing (which is what appears to be needed here) and editing.

      If the idea is that the person can update by clicking the URL the $check can be included in the param() call and added by the user (who presumably is in the loop) to show that the file should be updated:

      http://localhost/cgi-bin/sample_report.pl?value=xyz&check=1

      Update:
      (N.B. the &check=1 is added by the user, not received from the script, and, of course, one should think about adding a password for good measure...)
        And after the user clicks http://localhost/cgi-bin/sample_report.pl?value=xyz&check=1 this url sticks in the browser location field and when there is a refresh the same url is again submited to the server. (If you submit it in POST it won't do any better)