文本区域值未出现在 $_POST 对象上
伙计们,我对此感到摸不着头脑。
我有这个网站,它基本上包含一些由用户填写的表格。然后,用户可以以人类可读格式(pdf)或机器可读格式(xml)下载该信息,但我在提交文本框时遇到了一个小问题。
我有其中一些,例如在描述部分,但是当我访问 $_POST['Desc_Desc_desc'] 值时,它是空的,即使我可以看到文本区域上的内容。奇怪的是,当我使用 firebug 检查元素时,它显示该元素就好像它没有内容一样。
任何人都可以弄清楚是什么导致了这种奇怪的行为吗?
Guys, im scratching my head around this one.
I have this website that basically contains a few forms that are filled in by the user. The user then can download that information in human readable format (pdf) or machine readable format (xml) but I'm having a slight problem submitting textboxes.
I have a few of them, for instance in the description section, but when i access the $_POST['Desc_Desc_desc'] value, it's empty even though i can see content on the textarea. The weird thing is that when i use firebug to inspect the element, it shows the element as if it had no contents..
Can anyone figure what is causing this strange behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
service_level_library.buttons.prepForSubmit
中,文本区域与表单的其余部分一起通过 DOMcloneNode
方法。这会复制 HTML 元素属性,但不会复制 DOM 属性。 (有时 DOM 元素节点属性有一个相应的属性< /a>,因此更新属性会影响属性,这可能会使 DOM 属性看起来正在被复制。)而 textarea DOM 对象 具有
value
属性,textarea HTML 元素 没有相应的value
属性,因此value property 没有公开属性。因此,当您克隆节点时,(空)
value
属性将被复制,留下 元素的当前值(可通过value
属性访问)。要修复脚本,请执行以下操作之一:
defaultValue
属性或在克隆之前设置节点的文本内容。这是有效的,因为克隆节点的当前值将设置为其初始值,并且文本区域的深层副本将复制其文本内容(其初始值的来源)。In
service_level_library.buttons.prepForSubmit
, the textarea is cloned along with the rest of the form via the DOMcloneNode
method. This copies HTML element attributes, but not DOM properties. (Sometimes DOM element node properties have a corresponding attribute, so updating the property affects the attribute, which can make it appear that DOM properties are being copied.)While textarea DOM objects have a
value
property, the textarea HTML element doesn't have a correspondingvalue
attribute, so thevalue
property isn't exposing an attribute. Thus when you clone the node, the (empty)value
attribute is what gets copied, leaving the current value of the element (as accessible via thevalue
property) behind.To fix your script, do one of:
defaultValue
property or setting the text content of the node, before cloning. This works because the current value of the cloned node will be set to its initial value, and a deep copy of a textarea will copy its text contents (the source of its initial value).尽管在代码中我看到一个名为
Dep_desc
和 idDep_Desc_Desc
的文本区域,但你在问题中说 $_POST['Desc_Desc_desc'] 。那么你应该写$_POST['Dep_desc']
,即另外,
textarea
没有value
属性,因此在 html 中,您应该在开始标记和结束标记之间写入初始内容。HTML
PHP
注释
nl2br
:尊重 html 输出中替换\n
符号与
。htmlspecialchars
:防止可能的XSS
攻击。You say in your question
$_POST['Desc_Desc_desc']
, although in the code I see a textarea with nameDep_desc
and idDep_Desc_Desc
. Then you should write$_POST['Dep_desc']
, i.e. thename
of the<textarea>
instead of theid
.Also,
textarea
s don't have avalue
attribute, so in your html you should write the initial content between the opening and the closing tag.HTML
PHP
notes
nl2br
: Respect new lines in the html output replacing the\n
symbol with<br />
.htmlspecialchars
: Prevent possibleXSS
attacks.我使用 firebug 来分析发送到脚本的内容
表单数据正在正确发送
底线:表单不会提交给预期的收件人。
I used firebug to analyze what gets sent to your script by
The form data is being sent correctly
Bottom line: the form does not get submitted to the intended recipient.
我遇到了类似的问题,但后来我发现在底部的某个地方,我对另一个空元素重复使用了相同的名称。这也消除了 var_dump、print_r 中我所需的元素。花了一段时间才把它弄出来。
I had a similar issue but later I found out that somewhere at the bottom, I had reused the same name for another element which was empty. That wiped off my required element at var_dump, print_r as well. It took a while to get that out.