user2217702
user2217702

Reputation: 13

How can I determine which submit button that is pressed through PHP

I have two submit buttons in my form. One button for publishing the article immediately and one button for saving the article as a draft. How can I manage through PHP, not JavaScript, to detect which one that was pressed by the user when submitting the form? Appreciate any thoughts.

<button type='submit' name='publish' class='btn btn-success'>Publiser</button>
<button type='submit' name='draft' class='btn btn-success'>Lage som kladd</button>

Upvotes: 1

Views: 136

Answers (1)

Jon
Jon

Reputation: 437336

Check which of the two names is an existing key inside $_POST:

if(isset($_POST['publish'])) { ... }
else if(isset($_POST['draft'])) { ... }

Upvotes: 10

Related Questions