Skip to main content
Inspiring
July 21, 2011
Answered

Refresh/Recycle button - working around it with form submittals

  • July 21, 2011
  • 1 reply
  • 883 views

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 ?

    This topic has been closed for replies.
    Correct answer Owainnorth

    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.

    1 reply

    Owainnorth
    Inspiring
    July 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.

    Inspiring
    July 21, 2011

    Are there any other approaches, other than cflocation ?

    Anything I can with session vars ?

    Owainnorth
    OwainnorthCorrect answer
    Inspiring
    July 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.