I have an app built from laravel and I hosted it today. One of the users called me today saying that he entered a data twice (with different id's). So there was double entry. The reason for this was that the internet went off while he was filling up the details and he tapped the submit button. Now the 'no internet' error on chrome displayed and once the internet was back up, he refreshed it 3 times and the data was entered 3 times. He thought that he was still on the form filling view so he refreshed 3 times. Now how can I prevent this from happening? Is this possible?
After filling the form you could redirect to another page to display the "success" message. So if someone refreshes that page he just gets the "success" message again without the POST request before it that creates the data.
@FTIERSCH - At the moment, I have return redirect back with a message. Shouldn’t that do the same thing as what you have mentioned? Or do I have to redirect to a page other than the form page?
As you mentioned, the user refreshed 3 times and the data got entered 3 times. But this couldn't happen like this. As soon as he had refreshed, he would have got a popup saying confirm form submission. And after responding to that only the form would have got submitted and the data would have entered in the database.
So according to the workflow, the page would have redirected with displaying the appropriate message.
@TUSHAR2004 - This makes more sense. Now it could have been that he tapped the submit button twice thinking it wasn’t being submitted. How can I tackle that if that is the case? I mean pressing the button fast 3 times makes it enter 3 datas. How do I avoid doing that
That's a "normal" risk you're taking. But if it's a logical problem for your application you could check before inserting if the same user has entered data in the last... 10 seconds or something like that and then throw an error if that happened.
@FTIERSCH - This seems like the better solution.
429 abort seems to be a good solution but I don’t want the user to be presented with the http error code but rather a simple message bag would do.
@PICKAB00 - abort(429) will just throw appropriate exception, you can still display a message. Always remember to return appropriate HTTP status codes.