www.webdeveloper.com
Results 1 to 8 of 8

Thread: Stop User from resubmitting form by pressing back button

  1. #1
    Join Date
    Aug 2009
    Posts
    22

    Stop User from resubmitting form by pressing back button

    I'm making a site that has a form that allows a user to post info to the site, after they have posted they are redirected to a page with the info they just provided but form this page they can press the back button and then get the form again with all the info they filled in. how can i prevent them from just hitting submit again and getting a second copy of this info.

  2. #2
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043

  3. #3
    Join Date
    Aug 2009
    Posts
    22
    I dont want to disable the back button I just want to have the page either redirect to something else or clear out the form so that its blank

  4. #4
    Join Date
    Jul 2009
    Posts
    35
    you should handle that on your server side code. Before you save anything to your database(which Im assuming youre doing so) you should check for repeated content.

    For instance if the user is sending a comment through a form then check that theres no comment under the same user name, with EXACTLY the same text content in the database before you even try to save it. If there's repeated content then just redirect the user to a page telling them that this form has already been submitted.

  5. #5
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043
    Quote Originally Posted by adamscott421 View Post
    I dont want to disable the back button I just want to have the page either redirect to something else or clear out the form so that its blank
    Did you follow the second link of that Google page? The discussion is relevant.

  6. #6
    Join Date
    Mar 2008
    Posts
    73
    Or you could redirect to the previous page form after it has been submited and display the form again.

    If you don't what the vistor to be able to resubmit the form on the page which the form was processed after pressing the back. Then that can never happen. The form will have to be submited again.

    You could use JavaScript cookies, saving a cookie of the current time and date the form was submited. So when the user presses the back button you could just check the cookie and compare how previous ago the form was submited then disable the url of the submit button/the action attribute of the form. Perhaps displaying a message "You've already submitted this form in the last 3 minutes. Please wait for ten minutes to submit another"

    You could compare the data in the database with the submited data and the time at which it was submited. Therefore determining whether the content in the database and the submited one is from the same vistor.

    However if you want the user to not be able to resubmit the form at the page where the form was submitted at after pressing the back button/refreshing and be able to see the contents of that page then that can't happen.

  7. #7
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    Do everything dynamically on the same page... including your "Thank you, this is what you submitted...etc." that is in the page you are redirecting them to. The Back Button will take the to the page before the form and the Refresh Button will present a New Form without data. Easy to do in a php page and also in a html page... just embed the php.
    ...but stupidity is terminal.

  8. #8
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    588
    Try someething like this:

    <body ... onload="document.forms[0].reset();">

    Every time this page loads, whether going forward or backward, the form will clear.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles