php 无法通过 post 方法获取 textarea 的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16066731/
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
Cannot get the value of a textarea via post method
提问by medo ampir
It is a very simple form as in the code below:
这是一个非常简单的形式,如下面的代码所示:
<form method="POST" action="news.php?nid=2">
<textarea id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
<input type="submit" class="button" style="float: right; cursor:pointer;" value="Comment">
</form>
but in the news.php i cannot get the value of "txtcomment"
但在 news.php 中我无法获得“txtcomment”的值
echo $_POST['txtcomment'];
it returns nothing...
它什么都不返回......
回答by Sverri M. Olsen
It is because you need to name the textarea:
这是因为您需要为 textarea 命名:
<textarea name="txtcomment"></textarea>
The id
parameter does not have anything to do with how forms work (with the exception of label
s, but that is not important here).
该id
参数与表单的工作方式无关(label
s除外,但这在这里并不重要)。
回答by mohammad mohsenipur
textarea name must be txtcomment not id like
textarea 名称必须是 txtcomment 而不是 id 之类的
<form method="POST" action="news.php?nid=2">
<textarea id="txtcomment" name="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
<input type="submit" class="button" style="float: right; cursor:pointer;" value="Comment">
</form>
回答by Richard
Specify the name attribute of the textarea.
指定 textarea 的 name 属性。
回答by Tamil Selvan C
Add name attribute in textarea
在 textarea 中添加 name 属性
<textarea id="txtcomment" name="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea>
回答by Hendrik
you need to have an attribute name with txtcomment in it, you have an attribute 'id'
你需要有一个带有 txtcomment 的属性名称,你有一个属性“id”
回答by bwoebi
You have to define a name attribute (the id attribute is possible but not necessary).
你必须定义一个 name 属性(id 属性是可能的,但不是必需的)。
<textarea name="txtcomment" ...>
回答by JRL
It's not id="" that names the field in your array, it's name="".
命名数组中的字段不是 id="",而是 name=""。
<textarea name="txtcomment" id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />