Re: perl cgi - refresh question
by pfaut (Priest) on Apr 15, 2003 at 12:02 UTC
|
Separate the update and report functions into two CGI scripts. After performing the update, issue a redirect to the report script. Then, if the user hits refresh, they'll only be refreshing the report and not the data submit.
| 90% of every Perl application is already written. ⇒ | | dragonchild |
| [reply] |
Re: perl cgi - refresh question
by zby (Vicar) on Apr 15, 2003 at 11:52 UTC
|
How about adding one more unique parameter and checking every time if this particular value of that parameter was allready used? | [reply] |
Re: perl cgi - refresh question
by jonnyfolk (Vicar) on Apr 15, 2003 at 12:15 UTC
|
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. | [reply] [d/l] |
|
|
The problem is that when the page is refreshed than the identity variable will be resent.
| [reply] |
|
|
| [reply] |
|
|
|
|
Re: perl cgi - refresh question
by kiat (Vicar) on Apr 15, 2003 at 15:04 UTC
|
You might want to try this...
When the form is submitted, send a cookie to the client's browser. So when the page is refreshed, have your code check for the presence of the cookie. If the cookie is present, it means the entry has already been added so have the script print a message such as "Your submisstion has already been processed".
What if the user has disabled cookies? In this case, when the form is accessed, set a cookie to the client's browser. When the form is submitted, check for the presence of this form-accessed cookie. If no cookie is present, it means cookies have been disabled and so the submission will not be processed. In other words, have the script check for the presence of cookies before allowing further processing. | [reply] |
Re: perl cgi - refresh question
by empeka (Initiate) on Apr 15, 2003 at 16:41 UTC
|
I'm a bit hazy on HTML META tags, but the Refresh tag can have a target (and defaults to itself if none is set.)
With the CGI module use,
my $location = $query->url();
Which should return the full URL without state information (e.g. query parameters) and set the Refresh: target to $location.
--
Fundamentally, there may be no basis for anything. | [reply] |
Re: perl cgi - refresh question
by Anonymous Monk on Apr 15, 2003 at 17:04 UTC
|
Can you check the REFERER environment variable?
I would guess that if the REFERER is the form, go ahead and update the text file, but if the REFERER is blank (refresh), don't update the text file. | [reply] |
|
|
| [reply] |
Re: perl cgi - refresh question
by isotope (Deacon) on Apr 16, 2003 at 16:07 UTC
|
This is really what POST is for -- submitted data should be POSTed, and if the user tries to reload, most browsers will ask if he really wants to resubmit the info. Provide a 'refresh this page' link to sample_report.pl if you want, following it will result in a GET request with no submission.
--isotope
http://www.skylab.org/~isotope/
| [reply] |
Re: perl cgi - refresh question
by rupesh (Hermit) on Apr 16, 2003 at 04:19 UTC
|
Thanks to all you people.... I didn't expect such a great response... Man!! what a site!... Anyhow, as per your suggestions, i'm going to try it one by one... I'll let you guys know once i've tested each one of 'em. Once again... THanks to all!! | [reply] |