1

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?

0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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