如何在 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? //;
?>
最佳答案
您将在 $_POST 数组中找到该名称。
<?php
print_r($_POST);
?>
这样您将看到 $_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>";
}
关于php - 在PHP中获取提交按钮的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7074931/