Cannot get the value of a textarea via post method [closed]

梦想的初衷 提交于 2019-12-07 17:24:52

问题


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"

 echo $_POST['txtcomment'];

it returns nothing...


回答1:


It is because you need to name the textarea:

<textarea name="txtcomment"></textarea>

The id parameter does not have anything to do with how forms work (with the exception of labels, but that is not important here).




回答2:


Specify the name attribute of the textarea.




回答3:


Add name attribute in textarea

<textarea id="txtcomment" name="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea>



回答4:


you need to have an attribute name with txtcomment in it, you have an attribute 'id'




回答5:


You have to define a name attribute (the id attribute is possible but not necessary).

<textarea name="txtcomment" ...>



回答6:


textarea name must be txtcomment not id like

<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>



回答7:


It's not id="" that names the field in your array, it's name="".

<textarea name="txtcomment" id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />


来源:https://stackoverflow.com/questions/16066731/cannot-get-the-value-of-a-textarea-via-post-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!