Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name of submit button in PHP

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? //;
?>
like image 201
uzair Avatar asked Aug 16 '11 07:08

uzair


1 Answers

You will find the name in the $_POST array.

<?php
print_r($_POST);
?>

This way you will see everything in the $_POST array.

You can iterate through the array with:

foreach($_POST as $name => $content) { // Most people refer to $key => $value
   echo "The HTML name: $name <br>";
   echo "The content of it: $content <br>";
}
like image 56
Devator Avatar answered Oct 27 '22 14:10

Devator