Multiple Submit Button in a Single form with PHP


Do you know how to use two or more submit button in a single <form> ?

This is a critical problem while doing some professional websites!. You may face this situation in a project that needed two or multiple submit buttons!. Don’t worry this is not a Rocket Science!!. I will let you through this stuff  using PHP Programming!

See the Example Form it has two submit buttons:


if($_POST['submit1'] != '')
echo "You hit the button 1";
if($_POST['submit2'] != '')
echo "You hit the button 2";


<head><title>Multiple Submit button Solved with PHP!</title></head>
<form action="" method="post">

<h2> Hit the Submit Button</h2>

<input type="submit" name="submit1" value="btn1" />
<input type="submit" name="submit2" value="btn2" />


The above program solved the problem so easily, Let me tell how this works.

Actually when you hit the first button the PHP code will check whether you hit the First Submit button or Second with the help of  “If” Condition.

We have given values to the two submit buttons in line. 21 and 22. “btn1″ and btn2”. After you hit the submit button “IF” Condition will check whether it is empty or having some value in $_POST[‘submit1’] and $_POST[‘submit2’] .

If it is not empty then it will print out the echo Statement. So easy right?. Now you can use as many as Submit Button you want, just give different values to the submit buttons and write the if conditions to do the magic!

4 thoughts on “Multiple Submit Button in a Single form with PHP

  1. Wow, awesome blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is fantastic, as well as the content!. Thanks For Your article about Multiple Submit Button in a Single form with PHP : .

Leave a Reply

Theme: Overlay by Kaira