-1

My form consists of 2 clickable buttons:

echo '<input id='99999' type=\'submit\' name=\'send\' class=\'btn btn-default\' value=\'Some Action'/>';
echo '<input id='99988' type=\'submit\' name=\'send\' class=\'btn btn-default\' value=\'Another Action'/>';

Therefore the 2 buttons are loaded in my view, visible as Some Action and Another Action.

Moving over to my controller:

echo ($_POST['send']);

prints out Some Action and Another Action when clicked on, accordingly.

Unfortunately, I want the id field to get passed to the POST. (Want the controller to print 99999 and 99988). How can I make this happen?

I also tried echo <button ... > in the view but that did not pass the POST at all.

  • 1
    Only the name and value attributes of the inputs are passed when you post a form. – Pablo Digiani Nov 08 '15 at 20:26
  • You could use 2 forms and put a hidden input in both with the correct name - value pair. And the correct button. – jeroen Nov 08 '15 at 20:28
  • What can I do to pass the integer to the POST and display the text on the button? I can change the attributes of the button/input accordingly. –  Nov 08 '15 at 20:29
  • @jeroen I don't need to pass the text, only the integer field. I'm sure there is an easier way. –  Nov 08 '15 at 20:29
  • 1
    Possible duplicate of [HTML Submit-button: Different value / button-text?](http://stackoverflow.com/questions/4171664/html-submit-button-different-value-button-text) – Mike Nov 08 '15 at 20:34
  • @john It was just an example, the solution you accepted or Ajax are others. It all depends on your needs. – jeroen Nov 08 '15 at 22:16

1 Answers1

2

You can use the <button> element for this:

<button value='99988' name='send' class='btn btn-default'>Another Action</button>
Mike
  • 23,542
  • 14
  • 76
  • 87