How do I get the name of the submit button in PHP?
I got the value of submit button, but I could not find any code to get the name of the button. Below is the code I have written.
<form name="form1" method="post">
<input type="submit" value="hello" name="submitbutton">
</form>
<?php
echo "Value of submit button: " . $_POST['submitbutton'];
echo "Name of submit button: " . // What should I do here? //;
?>
You will find the name in the $_POST array.
This way you will see everything in the $_POST array.
You can iterate through the array with:
Its like any other POST variable, the name will be in the $_POST array. The name is the key in the $_POST array.
'submitbutton'
is the name of your submit button. you can get the names of super global $_POST array elements with array_keys() function