views:

15

answers:

1

Lets say I have a really simple html form:

<form action="./whatever.php" method="POST">
    <input type="submit" name="TheButton" value="Apples">
</form>

Which of course makes the button the user sees say Apples. I want the post request to be TheButton=Oranges ... Is there a simple way to deal with this in HTML, or will I be need to do something with a action=javascript ?

+2  A: 

The simple way is:

<button type="submit" name="TheButton" value="Oranges">Apples</button>

… but this will break in Internet Explorer (IIRC, up to and including version 7).

If you only have one button to deal with then:

<input type="submit" value="Apples">
<input type="hidden" name="TheButton" value="Oranges">

… will work fine.

Otherwise the best approach is to use server side logic:

<input type="submit" name="TheButton_Oranges" value="Apples">

And look for a value which starts with TheButton_ and then extract the value from the name. It is an ugly hack, but it is reliable and doesn't depend on client side JS.

David Dorward