dannyd Posted September 16, 2008 Share Posted September 16, 2008 I created a form and if the user hits submit it sends the form but if they refresh the page it will sumbit again. Is there a way to restrict the submission to only once ? So if they hit refresh it won't re-send ? Quote Link to comment Share on other sites More sharing options...
envexlabs Posted September 16, 2008 Share Posted September 16, 2008 You could set a cookie, or a session variable on submit, but i'm not sure if that's the best way to go about it. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 16, 2008 Share Posted September 16, 2008 You could simply populate a hidden field in the form when the page loads with a unique value (i.e. datatime+rand() number). Then when processing that page first check if any existing records have that value. If so, do not add the duplicate entry. If not, store the new record, including the unique value. Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted September 16, 2008 Share Posted September 16, 2008 What if it is just a form used to send email and there is no database interaction? Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 16, 2008 Share Posted September 16, 2008 What if it is just a form used to send email and there is no database interaction? Fine, make me think a little harder. Here's a probably better approach. When the form is submitted to the processing page, go through the normal validation procedures and if everything passes take whatever action is required (save data to DB, send email, etc.). THEN, do a header redirect to a confirmation page (e.g. "Thank you for your submission"). Then if the user refreshes the page they will just keep seing the confirmation page and the submission won't be processed again. Quote Link to comment Share on other sites More sharing options...
thesaleboat Posted September 16, 2008 Share Posted September 16, 2008 Thank you, mine works fine now, don't know about the guy who actually asked the original question, but thanks again I should have thought of that a while back. Quote Link to comment Share on other sites More sharing options...
dannyd Posted September 17, 2008 Author Share Posted September 17, 2008 Thank you. Never thought of using a simple redirect. Kinda feel stupid now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.