嵌套输入元素似乎没有出现在 dom 中
我正在为客户端构建一个 WordPress 插件,它可以完成许多工作。
我的目标是简单地获取一些 html 中的所有输入标签并使用数据。
我有一些 html(包含输入)
用户填写输入并单击“保存”。
Javascript 将整个 html 放入另一个隐藏输入中以用于发布目的。
然后,我从发布的项目中检索 html,即: $_POST["my_html"]
我使用 DOM 获取输入元素。 getElementsByTagName。
但输入值是空的。
我做错了什么吗?这可以做到吗(上图)?
Im building a wordpress plugin for client that does a number of jobs.
My goal is to simply get all the input tags in some html and use the data.
I have some html(that contains inputs)
The user fills the inputs in and clicks save.
Javascript puts the entire htmlinto another hidden input for POSTING purposes.
I then retrieve the html from posted item ie: $_POST["my_html"]
I get the input elements using the DOM. getElementsByTagName.
But the input values are EMPTY.
Am I doing something wrong. Can this be done (above) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为何选择如此艰难的道路?只需正常提交表单并从 $_POST 获取值即可。至于你的方法,我的猜测(因为没有提供代码)是你尝试将整个 DOM 元素添加为字符串。您需要设置每个元素的值(element.value)而不是整个元素。如果可以提供一些代码,我可以澄清我的答案。
Why choose such a difficult path? Just submit your form normally and get the values from $_POST. As for your method, my guess (since no code is provided) is that you try to add whole DOM element as a string. You need to set each's elements value (element.value) not the whole element. I could clarify my answer if some code could be provided.
序列化表单的正确方法不是存储其 html 标记。您应该存储键值对,它可以通过多种方式整齐地序列化,JSON 是一种非常流行且易于掌握的方法。
还可以将表单直接提交到处理脚本,这是自 HTML 2.0 以来一直有效的解决方案。
The correct way to serialize a form is not to store its' html markup. You should be storing key-value pairs instead, which can be neatly serialized in a number of ways, JSON being a very popular and easily graspable method.
There's also the possibility of submitting your form directly to the handling script, which has been a working solution since HTML 2.0.