Question

I'm trying to get the value of a button when it is clicked, because I got multiple buttons depending on how much data I got. So I need to know which button did I click. I got the code for the button like below.

<button type="submit" data-multiship-item-update="" class="action split" data-role="split" data-flag="0" value ="<?php echo $index ?>" <?php if ($reduce >= (int)$item->getQty()):?> disabled="disabled" <?php endif; ?>><span><?php /* @escapeNotVerified */ echo __('Add item(s) to Address') ?></span></button>

So the question is, how can I get the value of the button when I click it?

Was it helpful?

Solution

I got the answer my self by adding name to the button, and get the value by getPost("button name") in the controller like code below.

Button :

 <button type="submit" name="btn" data-multiship-item-update="" class="action split" data-role="split" data-flag="0" value ="<?php echo $index ?>" <?php if ($reduce >= (int)$item->getQty()):?> disabled="disabled" <?php endif; ?>><span><?php /* @escapeNotVerified */ echo __('Add item(s) to Address') ?></span></button>

Controller :

$btn = $this->getRequest()->getPost('btn');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top