2011-08-16 38 views
5

如何在php中獲取提交按鈕的名稱,我得到了提交按鈕的值,但coulnot發現 任何代碼獲取按鈕的名稱,下面是我寫的代碼。獲取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//; 
?> 
+1

是不是提交按鈕是你的名字嗎?比如你如何訪問沒有ID的元素?在你的例子中,你使用它的名字來獲得價值(擊敗我爲什麼)。所以我不知道你想在這裏看到什麼。 –

回答

4

您將在$ _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>"; 
} 
5

'submitbutton'是您的提交按鈕的名稱。 可以用array_keys()功能

$postnames = array_keys($_POST); 
1

它像任何其他變量POST得到超級全球$ _POST數組元素的名稱,該名稱將是$ _POST陣列英寸該名稱是$ _POST數組中的鍵。