Nowadays, Magento is leading the E-commerce CMS just because of the vast community of Magento Developers. Magento 2 comes with tons of rich helpful features and extensible code functionality that helps Business store owner acquire Magento without any hassle. Stepping into Magento 2 by creating first “Hello World” module, Magento developers are always playing with code and create new extensions those help store to kick off the competition. Magento 2 admin’s stores configuration section plays an important role while creating settings for your module.

A lot of our users ask us to come up with solution on creating a button in Magento 2 stores configuration section, where the button can be used to launch different event actions for an extension. We usually call some controller via Ajax and return the result.
Seems difficult, but it is quite easy, simply follow these steps.

Firstly, you need to add button as a field in “System.xml” configuration file by adding below code to app\code\Vendor\Extension\etc\adminhtml\

Now, you need to create another file “Button.php” file at app\code\Vendor\Extension\Block\System\Config\ using below code.

Lastly, we need to create “Button.phtml” file at app\code\Vendor\Extension\view\adminhtml\templates\system\config\ to draw button using following code.

That’s, it. Whenever the button is clicked, it triggers an ajax request to the controller where we can process something and lastly return the result.

Feel free to drop me a line in the comments below & don’t forget to hit the stars if this code works for you.

Happy Coding!

Click to rate this post!
[Total: 19 Average: 3.8]