1

I am trying to create two submit button in my form

<form id="form-input-wrapper" action='test.php'> //form items.. //form items.. <button class="btn btn-primary" type="submit" value="old">first button.</button> <button class="btn btn-primary" type="submit" value="new">second button</button> </form> 

My question is how to distinquish which button the user clicks in my test.php page?

2
  • 1
    Give the buttons a name and check if they are set and/or have values after submit Commented Jul 24, 2014 at 21:02
  • I think you want the name attribute. Commented Jul 24, 2014 at 21:02

2 Answers 2

2

You need to add the name attribute to your buttons

<button class="btn btn-primary" type="submit" name="old" value="old">first button.</button> <button class="btn btn-primary" type="submit" name="new" value="new">second button</button> 

The php code to use would look like:

if ($_SERVER['REQUEST_METHOD'] === 'POST') { //something posted if (isset($_POST['old'])) { //old } elseif (isset($_POST['new']){ //new } } 

related question: How can I tell which button was clicked in a PHP form submit?

Sign up to request clarification or add additional context in comments.

Comments

1

Use button name tag and check them in php:

<button name="subject1" type="submit" value="HTML">HTML</button> <button name="subject2" type="submit" value="CSS">CSS</button> 

And in php:

<?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ( isset($_POST['subject1']) ) { // first button is clicked } elseif ( isset($_POST['subject2']) ) { //second button is clicked } } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.