Skip to main content
Inspiring
September 17, 2008
Question

Why is form data re-submitting on page refresh?

  • September 17, 2008
  • 5 replies
  • 592 views
I'll start out by saying this is my first app using Application.cfc, and I'm not sure I fully understand how to really use it. With that said, I have the cfc with a cflogin script in it. After the login, I get sent to the index page and that works fine. However when I refresh the index page, I seem to log in again as the browser seems to be saving the form data. I also noticed that this happens on other forms to, so that it will keep inserting data into the database. How do I stop this from happening?
    This topic has been closed for replies.

    5 replies

    EnergyFedAuthor
    Inspiring
    September 17, 2008
    Great, this helps a lot.. I have no idea why I'm finding the application.cfc so hard to figure out? Thanks for all the suggestions!
    BKBK
    Community Expert
    Community Expert
    September 17, 2008
    Your Application.cfc and login code look fine. Some suggestions:

    1) <cfset THIS.sessiontimeout = createtimespan(0,0,20,0)>
    2) <cfset THIS.ScriptProtect = "all">
    3) onSessionStart and onSessionEnd may not return anything. Remove the cfreturn tags.
    4) Initialize the structure application.loggedInUsers in onApplicationStart using, for example,
    <cfset application.loggedInUsers = structNew()>


    Inspiring
    September 17, 2008
    EnergyFed wrote:
    > ...Why would you not want to put it in the application.cfc?

    That example is very basic and does it on one file to simply delivering
    the example. So somebody studying it doesn't have to put together logic
    in multiple files to see the process from start to finish.

    But it has the limit you are experiencing. By having it in the
    application.cfc, this code is part of every request received by the
    server. So this mean the form data is part of the request that sent
    back your index page after login. So if that page is refreshed, then
    the form data is resubmitted by the browser and your application
    responds to it again.

    You either need to make the handling in the CFC smart enough to not
    respond to improper requests, or move the logic out to other processing
    that is not part of every request.


    EnergyFedAuthor
    Inspiring
    September 17, 2008
    Other than on the index page after login, all of the other form submissions seem to be working without it trying to resend the info.

    As for the login code, I was just following the LiveDocs example and they seemed to have it there. Why would you not want to put it in the application.cfc?
    Inspiring
    September 17, 2008
    If this were my application, I would not have the login code in the application.cfc. It would be elsewhere. My onRequestStart function would check the login status and react accordingly.

    Regarding form re-submissions on page refreshes. That might be beyond your control. Every time I do it I get asked if I want to re-submit the form. Assume your users will also get asked and do something with your code to handle it.