1

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.

2 Answers 2

1

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.

3
  • I have give name to Save button. Although I'm not getting it in controller.
    – m2dev
    Nov 28, 2019 at 7:59
  • You can NOT use the same . How the same name value of two input fields cannot post right. This is basic HTML concept
    – Amit Bera
    Nov 28, 2019 at 8:00
  • I have updated question. please check.
    – m2dev
    Nov 28, 2019 at 8:01
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.