I have a 'contact us' html form and I'm giving gift for each member that click submit. I want to make sure that a user doesn't submit twice (with different name and email). I can disable the button after click, but what will be the best solution to prevent submit after page refresh? Thanks
Asked
Active
Viewed 2,382 times
-1
-
1Can you show your code? The guessing game is too broad for SO – Sterling Archer Dec 27 '17 at 20:33
-
2Best solution? Serverside language and a database. – epascarello Dec 27 '17 at 20:34
-
StackOverflow is not for asking for suggestions. It's for posting code that you have written, but doesn't work. – Ruan Mendes Dec 27 '17 at 20:43
-
This is an "anti-forgery token". Add a hidden field to your form with a randomly generated number. If you see that number in multiple submissions, you know its a double-submit. If you also include a cookie token, this can be used to prevent CSRF attacks. – Dec 27 '17 at 20:50
3 Answers
1
Is to directly redirect from your POST
to a GET
request or page. if he/she refreshed it will refresh the other page. this is named Redirect After Post and you can read more about it here and in WikiPedia
An Example can be found here.

Muhammad Soliman
- 21,644
- 6
- 109
- 75
0
Two things that you can do and you should do.
- First disable the
Submit
button as soon as your client submits the form with valid information in it. So that he/she accidently doesn't send duplicate information in the form. - Second, which is more important. Is before you save this information in your database whatever that is MySQL, MongoDB or etc. You perform a query that checks whether the information provided by the user exists in your db already or not. If not then proceed as you do but if it does you can do error handling on the use case scenario as per your business logic.

Adeel Imran
- 13,166
- 8
- 62
- 77
0
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>

Avatar
- 14,622
- 9
- 119
- 198