1

When you submit a form, does the button that was clicked get posted also?

Blankman
  • 248,432
  • 309
  • 736
  • 1,161

3 Answers3

5

Yes it does. As long as you set both the name and value:

<INPUT name="submit" value="submit" type="submit"/>

In fact you can have multiple submit buttons on the same page and you can detect which one is clicked on by checking for this pair.

Keltex
  • 25,872
  • 11
  • 77
  • 111
1

Yes, submit buttons are submitted with their name/value.

But especially when doing i18n, it's recommended to rely only on the name, not the value though so you don't have to check for i18n'd values in your server-side code but just for the existence of certain POST arguments..

ThiefMaster
  • 298,938
  • 77
  • 579
  • 623
0

If it is part of the submitted form, yes.
When a form is submitted, every one of it's "input" elements are posted; and if you submit a form by clicking it's submit button (which is another input) you'll definitely post it too.
If you don't want to do that, you can always submit you form via javascript : form.submit();.
You can add a button element to your form and attach a function that submits the form to it's click event.

<button type="button" onclick="document.getElementsByTagName('form')[0].submit();">
    Submit the form!
</button>

That way you'll have a submit button inside your form that is not submitted:)

gion_13
  • 40,487
  • 10
  • 96
  • 107