Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  15] [ 4]  / answers: 1 / hits: 46520  / 12 Years ago, fri, march 2, 2012, 12:00:00

If I have multiple HTML tags with separate submit forms, how do I know which when was posted in the PHP file that processes the form's data?


More From » php

 Answers
110

The easiest way is to name your submit buttons unique to the form. You can also use this if you have multiple submit buttons for a SINGLE form (eg - submit and save, submit and return, submit and exit)



 <input type=submit name=action value=Save>
<input type=submit name=action value=Return>
<input type=submit name=action value=Exit>


The $_POST array (or $_GET/$_REQUEST) will contain the key action with the value of the enacted button (whether clicked or not).



As a rule, I avoid passing hidden text fields, etc, that are unnecessary - simply to keep the code more clean.



So. For your application, I'd give your submit button values as such:



<form id=Form1>
<input type=submit name=action value=Form1>
</form>

<form id=Form2>
<input type=submit name=action value=Form2>
</form>

<form id=Form3>
<input type=submit name=action value=Form3>
</form>

[#87079] Thursday, March 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hollievalerier

Total Points: 431
Total Questions: 93
Total Answers: 105

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;