Html Textarea 值未随表单一起发布

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18816735/
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-29 13:27:51  来源:igfitidea点击:

Textarea value not getting posted with form

htmlposttextarea

提问by Juicy

I'm trying to input a textarea tag when I submit my form:

我在提交表单时尝试输入 textarea 标签:

<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>

<form action="sendConfirmation.php" name="confirmationForm" method="post">
   <input type="submit" value="Email" class="submitButton">
</form>

As you can see I've set the form="confirmationForm" attribute in my textarea tag. I've used Live HTTP Headers to catch the POST request and it is empty (so I know the problem is not in sendConfirmation.php, the problem is that the confirmationText is not being POSTed). I've searched the net and as far as I can see I've set it correctly.

如您所见,我在 textarea 标记中设置了 form="confirmationForm" 属性。我使用 Live HTTP Headers 来捕获 POST 请求并且它是空的(所以我知道问题不在 sendConfirmation.php 中,问题是没有 POST 确认文本)。我已经在网上搜索过,据我所知,我已经正确设置了它。

回答by Ahsan Shah

try to put it inside the form tag as follows... it should work

尝试将其放入表单标签中,如下所示......它应该可以工作

<form action="sendConfirmation.php" name="confirmationForm" method="post">
    <textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText"></textarea>

   <input type="submit" value="Email" class="submitButton">
</form>

however you can use the same approach as well but you need to provide the from id attribute then

但是您也可以使用相同的方法,但是您需要提供 from id 属性然后

<form action="sendConfirmation.php" id="confirmationForm" method="post">
   <input type="submit" value="Email" class="submitButton">
</form>

回答by dietbacon

You must put in the form attribute of the textarea the form's id, not it's name.

您必须在 textarea 的 form 属性中放入表单的 id,而不是它的名称。

try:

尝试:

<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>

<form action="sendConfirmation.php" id="confirmationForm" name="confirmationForm" method="post">
   <input type="submit" value="Email" class="submitButton">
</form>

source: http://www.w3schools.com/tags/att_textarea_form.asp

来源:http: //www.w3schools.com/tags/att_textarea_form.asp

回答by Elliot Lings

You need to put your textarea inside the form tag

您需要将您的 textarea 放在表单标签内

 <form action="sendConfirmation.php" name="confirmationForm" method="post">
    <textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>
    <input type="submit" value="Email" class="submitButton">
</form>

When a form is submitted everything inside it is sent, any inputs outside the form tag are ignored.

当表单被提交时,它内部的所有内容都会被发送,表单标签之外的任何输入都将被忽略。

回答by bara batta

Just Add Form="formId" attribute to TextArea tag and Assign Id to Form

只需将 Form="formId" 属性添加到 TextArea 标记并将 Id 分配给表单

<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>

<form action="sendConfirmation.php" id="confirmationForm" name="confirmationForm" method="post">
   <input type="submit" value="Email" class="submitButton">
</form>

回答by Shivanshu

I was having the same issue, got it resolved by adding method="post" in textarea.

我遇到了同样的问题,通过在 textarea 中添加 method="post" 来解决它。

回答by Ojas Kale

Make sure you are not missing out on name attribute of textarea tag. This happend to me in django.

确保您没有遗漏 textarea 标签的 name 属性。这在 Django 中发生在我身上。

回答by J. Ternent

Bit of a necro here but it's still high in the Google search rankings, so adding my 2 cents -- what finally worked for me was NOT using the form= attribute if the textarea is inside the form. Even though the name was the same as the form's name, it didn't work until I removed the form= bit. Tried defaultValue, tried putting some text in the textarea itself, none of those helped.

这里有点死机,但它在谷歌搜索排名中仍然很高,所以加上我的 2 美分——如果 textarea 在表单内,那么最终对我有用的是不使用 form= 属性。尽管名称与表单的名称相同,但在我删除 form= 位之前它不起作用。尝试了 defaultValue,尝试在 textarea 本身中放置一些文本,但这些都没有帮助。

回答by Panu Haaramo

I had disabled="disabled"attribute in my textarea. It will prevent submitting inputas well.

我曾disabled="disabled"在我的属性textarea。它也会阻止提交input

回答by taehyun lee

<form action="sendConfirmation.php" name="confirmationForm" method="post">
<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>
   <input type="submit" value="Email" class="submitButton">
</form>

<form action="sendConfirmation.php" name="confirmationForm" method="post" id="confirmationForm">

you need to add id in the form tag

您需要在表单标签中添加 id

textarea form="confirmationForm"match form id="confirmationForm"

textarea form="confirmationForm"比赛 form id="confirmationForm"

try it

尝试一下

回答by nqkhanh

Try to put it beside the form tag as follows... It should work.

尝试将它放在表单标签旁边,如下所示......它应该可以工作。

<form action="sendConfirmation.php" name="confirmationForm" method="post">
<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm"></textarea>
   <input type="submit" value="Email" class="submitButton">
</form>