在PHP中获取提交按钮的名称

uza*_*air 5 php submit form-submit

如何在php中获取提交按钮的名称,我得到了提交按钮的值但是找不到任何代码获取按钮的名称,下面是我写的代码.

<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? //;
?>
Run Code Online (Sandbox Code Playgroud)

hex*_*mal 5

'submitbutton'是提交按钮的名称.你可以使用array_keys()函数获取超全局$ _POST数组元素的名称

$postnames = array_keys($_POST);
Run Code Online (Sandbox Code Playgroud)


Dev*_*tor 5

您将在$ _POST数组中找到该名称.

<?php
print_r($_POST);
?>
Run Code Online (Sandbox Code Playgroud)

这样你就可以看到$ _POST数组中的所有内容.

您可以使用以下代码遍历数组:

foreach($_POST as $name => $content) { // Most people refer to $key => $value
   echo "The HTML name: $name <br>";
   echo "The content of it: $content <br>";
}
Run Code Online (Sandbox Code Playgroud)