Two submit buttons in a form – PHP

This post explains you how to use two or more submit buttons in a single HTML form using PHP technology.

HTML Part:

See the above code, there are two button I have used in the form,
First button with the name = “submit1”
Second button with the name = “submit2”

So, basically on submitting the form I’m going to check which button is clicked with the help of PHP program.

Here is the code for that:

The PHP code is simpler than you expected right?. Yes, of course, a simple IF condition can help you to find out which button is pressed. When you press the first submit button the form POST method will send value “btn1” to the server and when you press the second button it will send value = “btn2” to the server.

So, basically with the IF condition, you can check which of the button value is empty and which one has a value, then do the required operations you want with that. I’m here just printing the strings “you pressed button 1” or “you pressed button 1”.

Here is the entire code:

Also to see how the code works, see the DEMO here:



Related Posts

Leave a Reply