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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7074931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:57:53  来源:igfitidea点击:

Get the name of submit button in PHP

phpsubmitform-submit

提问by uzair

How do I get the name of the submit button in PHP?

如何在 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? //;
?>

采纳答案by Devator

You will find the name in the $_POST array.

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

<?php
print_r($_POST);
?>

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

这样您将看到 $_POST 数组中的所有内容。

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>";
}

回答by heximal

'submitbutton'is the name of your submit button. you can get the names of super global $_POST array elements with array_keys()function

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

$postnames = array_keys($_POST);

回答by Devraj

Its like any other POST variable, the name will be in the $_POST array. The name is the key in the $_POST array.

它与任何其他 POST 变量一样,名称将在 $_POST 数组中。该名称是 $_POST 数组中的键。