Comment

cloudranger

I found a few of the examples given here didn't work well for me - some didn't work at all (were off topic) or others either flashed the value in the button before posting the page, or IE returned more in the post variables than Firefox did. A couple of others whilst working still brought back both buttons so you had no idea which had been pushed.

I came up with my own variation based the version by kolibrizas in this article. My focus was to bring back exactly the same post variables on IE and Firefox (no extra rubbish) and support passing back values (other than the button name or text) in the button - ie bringing back a record key with the delete button.

<?php
print_r($_POST);
?>

<form action='test.php' method='post'>
<input type="hidden" name="" value="" id="ie-save">
<input type="hidden" name="" value="" id="ie-delete">
<button type="submit" onclick="document.getElementById('ie-save').value='save';document.getElementById('ie-save').name='save'" name="" id="save">SAVE</button>
<button type="submit" onclick="document.getElementById('ie-delete').value='1234';document.getElementById('ie-delete').name='delete';" name="" id="delete">DELETE</button>
</form>

The way I avoid bringing back any rubbish in the post variables is to not assign any names to any of the buttons until they are clicked.

As onClick relies on Javascript, in real life, this code snippet it wrapped in a PHP class that I call to generate a button. I identify the browser type and output a standard button string if it is not IE, and the above if it is. That way on a non IE browser there is no workaround code generated (ie the onClicks or hidden fields)