![](/img/trans.png)
[英]javascript unable to assign hidden input elements from HTML input tag
[英]hidden attribute in input tag from html form
我正在嘗試獲取發布的信息並使用以下代碼顯示信息:
PHP代碼:
$self = $_SERVER['PHP_SELF'];
if(isset($_POST['send'])){
$words = htmlspecialchars($_POST['board']);
print "<b>".$words."</b>";
}
HTML代碼 :
<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
<p><i>Comment</i></p>
<textarea name="board" rows="20" cols="10"></textarea>
<input name="send" type="hidden" />
<p><input type='submit' value='send' /></p>
</form>
上面的代碼將按我的意圖工作。 但是,如果我放棄了輸入名稱=“發送”,類型=“隱藏”,則單擊發送按鈕后將不會顯示用戶輸入消息。 為什么會這樣?
您需要在提交按鈕上添加name ='send',PHP代碼正在讀取表單元素的名稱,並且您尚未為提交按鈕指定一個。
<form action="<?php $self ?>" method=post> <!--$self is the directory of the page itself-->
<p><i>Comment</i></p>
<textarea name="board" rows="20" cols="10"></textarea>
<p><input type='submit' name='send' value='send' /></p>
</form>
另外,請注意-您可以將表單方法更改為GET而不是POST,以輕松查看要在URL欄中發送的表單數據。
這是因為您正在檢查是否已設置POST變量“發送”。 那就是您命名隱藏輸入的名稱。
您應該在提交輸入中添加一個name
。 例:
<p><input type='submit' name="submit_button" value='send' /></p>
現在在您的php中,檢查您的提交按鈕的name
。 在此示例中,我使用了“ submit_button”。 這是修改后的代碼示例:
$self = $_SERVER['PHP_SELF'];
if(isset($_POST['submit_button'])){
$words = htmlspecialchars($_POST['board']);
print "<b>".$words."</b>";
}
不必麻煩命名發送按鈕或其他任何東西,只需刪除該hidden
線即可。
並將您的php更改為...。
$self = $_SERVER['PHP_SELF'];
if(isset($_POST)){
$words = htmlspecialchars($_POST['board']);
print "<b>".$words."</b>";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.