Copy link to clipboard
Copied
I have a form which submits to result page
On the result page...
<cfif structKeyExists (form, "submit">
total=total+1
</cfif>
I notice if I press the "refresh" button on any browser, the total increases, which I don't want.
So I thought I could get around it by using structDelete(Form,"submit") , but it made no difference. Looking further into it, when I dumped form contents at the start of the results page, it appears the refresh button "undeletes" for the Form "submit" strucutre, which is why my total increases.
Any advice on a way around this ?
It's possible, we did something like that on our system as a double-safety mech, but it was to stop people hitting submit twice quickly rather than F5 issues.
At the *very* top of the processing page, do something like <cfset session.ProcessingRunning = true /> then false at the end of the page.
Then, wrap the code of the page in a <cfif NOT session.ProcessingRunning > or similar. But the code must be at the very top of the page to make sure it runs as soon as someone clicks.
Just think it out log
...Copy link to clipboard
Copied
Think about what happens when you press F5 - the request is sent again, with the form data, and the CF template is actually run, in its entirety, again. Therefore there's nothing you can do within the context of that page to get around that - the two threads are not aware of each others presence.
The standard way of dealing with it is to do a redirect. Something like this:
<cfif structKeyExists (form, "submit")>
<cfset total++ />
<!--- do any processing here, then... --->
<cflocation url="#cgi.script_name#" addtoken="false" />
</cfif>
That way when they hit F5, they will have a clear FORM scope.
Copy link to clipboard
Copied
Are there any other approaches, other than cflocation ?
Anything I can with session vars ?
Copy link to clipboard
Copied
It's possible, we did something like that on our system as a double-safety mech, but it was to stop people hitting submit twice quickly rather than F5 issues.
At the *very* top of the processing page, do something like <cfset session.ProcessingRunning = true /> then false at the end of the page.
Then, wrap the code of the page in a <cfif NOT session.ProcessingRunning > or similar. But the code must be at the very top of the page to make sure it runs as soon as someone clicks.
Just think it out logically, there's nothing complicated about it once you know exactly what you want to achieve.
Copy link to clipboard
Copied
What about attaching a random number to the form
Then the form processing page checks it against the last random number ?
(if they match, its a no go)
Copy link to clipboard
Copied
If you wanted to, you'll have to store all the recently submitted Form IDs somewhere though.