We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37638
    • 63 Posts
    I have a project that relies heavily on POST forms to update some custom DB tables. Typically, a user sees a list of items, clicks on an item to edit it (which loads a new page), makes the changes and then the form submits back to the original page. That page then updates the DB with a snippet.

    The problem is that if the user reloads the page, or goes forward then back the form gets resubmitted.

    How can I get around this? I was going to user a HEADER redirect, but so long as the forms get updated via a snippet the headers have long been sent. I thought about a plugin, but I don't have time (right now) to re-write all the snippets as plugins.

    Is there a better option I am missing?

    User Flow:
    Page 1->Edit->Page 1 with POST data

    Problem Flow:
    Page 1->Edit->Page 1 with POST data-> Page 2 <- (user hits back button)
      • 38290
      • 712 Posts
      hm, only way i've really worked around this is inherently by using AJAX but that doesn't solve it from happening just prevents js users from leaving the page in the first place
        jpdevries
        • 27708 MODX Staff
        • 2,502 Posts
        I am musing here but I think you have a couple possibilities (caution, read my sig). One thought is that you store your post in a session and then drop the session data into the query and you also need may want to double glove and use something like Sisyphus.js to prevent the data-loss on the back and forth.

        You may also want to consider preventing accidental page departures with something like: http://stackoverflow.com/questions/821011/how-do-you-prevent-javascript-page-from-navigating-away

        I am not sure if you want to prevent accidental form submission too. There are tonnes of way of skinning that cat.
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub