Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Refresh/Recycle button - working around it with form submittals

Participant ,
Jul 21, 2011 Jul 21, 2011

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 ?

695
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jul 21, 2011 Jul 21, 2011

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

...
Translate
Guide ,
Jul 21, 2011 Jul 21, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2011 Jul 21, 2011

Are there any other approaches, other than cflocation ?

Anything I can with session vars ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 21, 2011 Jul 21, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2011 Jul 21, 2011

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 21, 2011 Jul 21, 2011
LATEST

If you wanted to, you'll have to store all the recently submitted Form IDs somewhere though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources