John Davidson

php - Laravel: Submittng form multiple times breaks checkout process

0 comments
Message:


Creating an order in my custom Laravel shop takes some time, because of an third party API call. To prevent users from submitting the checkout form twice, I disable the submit bitton and show and replace it with a process icon via Javascript.


Nevertheless some customers can not wait 10 seconds to complete the process. They reload the page and submit the form again. In this case, the shop generates two orders.


Now I could prevent the form from sumbitting multiple times serversited with token match (Prevent Multiple Submitting in one button laravel). Actually, this solution will causes other issues. So I can not simply redirect the customer to the success-page, because the order process might not be complete. Otherwise the customer is stuck in the checkout page.


What is best practise for this problem?



My Answer:
One possible solution to this problem is to implement a form submission queue on the server side. When a user submits the form, you can add the form data to a queue and process it one at a time. This way, even if a user submits the form multiple times, the orders will be processed sequentially and duplicate orders will not be created.

Another option is to implement a form submission lock on the client side. When a user submits the form, you can disable the submit button and prevent any further submissions until the current submission is complete. This can be done using JavaScript to lock the form and prevent multiple submissions.

Additionally, you can also consider implementing a session-based check to prevent duplicate orders. When a user submits the form, you can store a flag in the session indicating that the order is being processed. If the user tries to submit the form again, you can check this flag and prevent the submission if an order is already in progress.

Overall, the key is to implement a combination of server-side and client-side checks to prevent duplicate orders while still providing a smooth checkout experience for your customers.

Rate this post

4 of 5 based on 3391 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us