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 ? Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/ 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. Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-642917 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. Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-642919 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? Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-642920 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. Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-642973 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. Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-642978 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. Link to comment https://forums.phpfreaks.com/topic/124497-restrict-number-of-submissions-on-form/#findComment-643917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.