在 DOM 中移动字段集会将它们排除在 POST 之外
我正在将 JQuery Formwizard 插件 (http://thecodemine.org/) 用于我的其中一个表单。该插件允许您在表单中添加和删除元素。好东西! 只是,我添加的表单元素不会包含在表单的服务器端处理程序上的 POST 变量中。怎么会?我的代码有点庞大,但这是我正在做的事情的想法:
<form id="wizard">
<fieldset id="fieldset_person1" class="step">
Name: <input type="text" name="person1[name]" />
</fielset>
<fieldset id="fieldset_order" class="step">
Amount: <input type="text" name="order[amount]" />
</fieldset>
</form>
<div style="display: hidden">
<fieldset id="fieldset_person2" class="step">
Name: <input type="text" name="person2[name]" />
</fielset>
</div>
然后将 fieldset_person2 字段集移动到 fieldset_person1 所在位置之后,并更新向导插件。但是当我提交表单时,不包含 person2 字段。我还尝试将 div 添加到表单本身,但如果它没有移动到正确的位置,它只会包含在 POST 中。
对此有什么想法吗?我没有主意了:/
I'm using the JQuery Formwizard plugin (http://thecodemine.org/) for one of my forms. This plugin allows you to add and remove elements to and from the form. Nice stuff!
Only, the form elements I'm adding don't get included in the POST variable on the server-side handler of the form. How come? My code is kinda huge but here's the idea of what I'm doing:
<form id="wizard">
<fieldset id="fieldset_person1" class="step">
Name: <input type="text" name="person1[name]" />
</fielset>
<fieldset id="fieldset_order" class="step">
Amount: <input type="text" name="order[amount]" />
</fieldset>
</form>
<div style="display: hidden">
<fieldset id="fieldset_person2" class="step">
Name: <input type="text" name="person2[name]" />
</fielset>
</div>
The fieldset_person2 fieldset is then moved after where fieldset_person1 is and the wizard plugin is updated. But when I submit the form, the person2 fields aren't included. I've also tried adding the div to the form itself, but then it only gets included in the POST if it was not moved to the correct spot.
Any thoughts on this? I'm all out of ideas :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜它不会进入表单,您可以向我们展示生成的源代码,也很高兴看到完成工作的代码
I'm guessing that it's not going into the form can you show us the generated source also would be good to see the code that does the work
只是一个猜测:确保您没有隐藏您的输入;隐藏的输入不随表单一起发送。
just a guess: make sure you're not hiding your inputs; hidden inputs are not sent with the form.
啊,我终于明白了。
显然,HTML/Javascript/JQery 组件不喜欢元素在 DOM 中移动。然而,创建新元素并不是问题。
我已将 fieldset_person2 重命名为 fieldset_person2_dummy 并将 _dummy 附加到该字段集中的所有其他 ID。当我想向表单添加页面时,我使用 JQuery 的 clone() 来克隆此字段集,更改所有 ID 并删除 _dummy,然后将元素附加到 DOM。就像魅力一样。
感谢大家的帮助,希望这有用。
Ah, I finally got it.
Apparently, HTML/Javascript/the JQery component doesn't like it when elements are moved in the DOM. Creating new elements however is not a problem.
I've renamed fieldset_person2 fieldset_person2_dummy and appended _dummy to all other ID's in that fieldset. When I want to add a page to the form, I use JQuery's clone() to clone this fieldset, change all ID's removing _dummy, and then append the element to the DOM. Works like a charm.
Thanks for the help guys, hope this is useful.