I've some problems due to multiple form submissions. I'm using laravel as framework and creating a browsergame (I know, there are millions) just for fun.
I've a page for buildings with a button "Construct" which is in a form (method="post").
If I hold Enter for 4-5 seconds many request will be fired and the user can create many records in the database.
I don't want an only client side fix like
$(document).on('submit', 'form', function() {
$(this).find('button:submit, input:submit').attr('disabled', 'disabled);
});
Because never trust the client.
Is someone here with a solution (maybe with laravel)?
Thanks in advance.
Best regards.
"Generate a random token. Put token in session. Put token in form as hidden field. On submit if token received is equal to the one in session do all the stuff on database and delete token from session."
"Using middleware for route group (laravel.com/docs/5.6/routing#route-group-middleware) you can View::share (laravel.com/docs/5.6/views#sharing-data-with-all-views) a random token and save on session."
Thanks @assistbss
You can control it in server side using csrf token. Your form will have a token for preventing cross-site request forgery, and you can access this token in your controller to identify the client uniquely. When a request coming to the controller you can check whether the client sending the request first time or not. If it is not first time you can return back. Example:-