cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle a magento form request?

How to handle a magento form request?

I created a button inside order view which is created in this way:

        $onclick = "submitAndReloadArea($('order_sendsms').parentNode, '" . $this->getSubmitUrl() . "')";
        $button = $this->getLayout()->createBlock(
            \Magento\Backend\Block\Widget\Button::class
        )->setData(
            ['label' => __('Send'), 'class' => 'action-save action-secondary', 'onclick' => $onclick]
        );
        $this->setChild('submit_button', $button);
        return parent::_prepareLayout();

but I don't really know where I should submit the button to. I tried creating a controller but it did not receive the request. My goal is to have a button, execute something in PHP and show a success or fail message. How to achieve this?

2 REPLIES 2

Re: How to handle a magento form request?

@catalinsen1956 

It'll be easy if you call Ajax on the click event of the button

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: How to handle a magento form request?

If you are in production mode and seeing this error (Invalid security or form key)

aaaaa.PNG

The run setup:upgrade and other respective commands. Then try click on the button.