Prevent users from sending new requests if the current request has not been completed

Is there a way in Laravel to prevent a user from making a new request if the current request has not been completed? I want to prevent users from submitting multiple requests as they may feel that the process is hanging due to slow internet connections. At the end of the day, each request will be create separate database transactions and bypass validation checks resulting in duplicate records - if the transactions are processed at the same time. Please note that the requests are not ajax requests, they are form submissions.

1 answer

  • answered 2018-11-13 08:24 Thomas

    @D. Petrov has a great suggestion in the comments about disabling the submit button while the HTTP request has not returned a response. I personally like it.

    However if you want another solution, you could require a token, similar to a CSRF token to identify each unique request. Than you can accept the token only the first time server sided and block all subsequent request using the same token after that.