I have created one custom form with two Buttons. 1 is Save and 2 is Submit.

When admin submit the form I have to check in controller which button is clicked.

<button id="save_btn" name="save" title="Save" type="submit" class="action-default scalable action-save action-secondary" value="save" data-ui-id="widget-button-0">
    <span>Save</span>
</button>

<button id="submit_btn" name="submit" title="Submit" type="submit" class="action-default scalable action-save action-secondary" data-ui-id="widget-button-1">
    <span>Submit</span>
</button>

In controller I have used

$post = $this->getRequest()->getPostValue();

$post = $this->getRequest()->getPostParams();

I'm getting all other data but not getting button data in the controller.

有帮助吗?

解决方案

You did a mistake. The button should have a name attribute

<button id="submit_btn" title="Submit"

should be

<button id="submit_btn" title="Submit" name="mysubmit"

A form will post those field whose has a name attribute.

其他提示

Here you can use simple JS to set one hidden value, set one hidden input and on click of button change the value of hidden field and trigger the submit from, by this way you will be able to get value in ->getRequest->getPost(); hope that will help you.

许可以下: CC-BY-SA归因
scroll top