How to Disable Submit Button on Form Submission in Magento 2

Collecting customer data is the most common requirement you may have addressed while performing customization in Magento 2 store or developing Magento 2 extensions. One of the best ways to do so is through forms, and for that, you need to create custom form in Magento 2.

We can get the data on the click event of the submit button and pass it to the database. In this process, what if the user press the submit button frequently while the data storing operation is still in the processing state? The users may do so because they may not get acknowledgment of their form submission.

It ends up storing multiple same data of the same user in the database and creating confusion.

In order to avoid such a situation, we need to prevent multiple form submissions, and it can be done using the below method to disable submit button on form submission in Magento 2

For instance, a user enters the required detail in the custom form and clicks on submit button. After clicking the button once, just disable submit button on the form submission until the data is still in the processing stage. It prevents unnecessary clicks as well as helps to improve the user experience too!

It gives acknowledgment to users that their data is getting processed and the next operation will be executed soon. Additionally, it helps you to prevent multiple form submissions also!

Perform the same using the below code.

Method to Disable Submit Button on Form Submission in Magento 2

Use the below code in form.phtml file located at app/code/Vendor/Extension/view/frontend/templates

That’s it! You can easily disable submit button on form submission in Magento 2 by implementing the above code.

Any doubts about this solution can be mentioned in the Comments section below.

I’d be happy to help.

Also, do share the post with Magento Community via social media.

Thank you.

5
(based on 2 Reviews)
How to Disable Submit Button on Form Submission in Magento 2

Dipak Vadher

Dipak is a Magento Developer at Meetanshi. Apart from work, he loves playing cricket with his friends. Traveling and exploring new places is something that he is passionate about.

Leave a Reply

Your email address will not be published. Required fields are marked *