I hope my question is clear and has an answer. This my Submit Button (not real code):
while... input type=submit name=$row['ID']
when I click the submit button I need to get its name in the next page. How?
I have different submit buttons and I don't know if the user chose the first, second, third, or x
button.
If the submit button is part of a form with a value, you can access it in the $_POST or $_GET data array on the following page. If your script doesn't know the name of the submit button, loop through the postdata to find it.
If you dont want to change your application design, you can do simply
It is not a beautiful solution, but may be appropriate for you
EDIT: matino's answer is more appropriate if it fits your use-case.
If I understand you correctly, you want to get/check the presence of "the_name" after the submission of the following form:
Now, all POST'ed data is available in PHP's
$_POST
superglobal, however PHP has no way of knowing which part of the data is the submit button.There are two possible ways around this:
isset($_POST['the_name'])
- this will tell you if the user submitted the form by clicking thethe_name
submit button (however, if the hitenter
, the variable would not be present).submit[the_name]
- this way you could find the name of the pressed submit button by looking atarray_keys($_POST['submit'])[0]
.Instead of assigning an id to the button name, use query string and submit to
your_script.php?id=$row['ID']
. Then on the next page use$_GET['id']
to get the button name.Based on your comment you actually need to find out if a button was pressed. Check the example below.
Here is a simple form with a username input and three buttons to perform a variety of actions on that username:
Once one of the
submit
buttons is pressed, we go to next_page.php and check to see which one it was and perform an action based on that.