当名称字段是数组时如何使我的表单粘住
我是一名在校最后一个季度的学生,正在从事一个项目。我使用 JQuery 来允许动态添加表单字段,因此我必须对名称字段使用数组,以便我可以从潜在的多个相同字段中收集信息。我还想使所述表单字段具有粘性。我搜索过 Google,搜索过 stackoverflow,还问过我的资深开发者丈夫(我应该看看我难倒他时他脸上的表情)。
我正在这样编写我的代码:
<input type="text" name="trip_date[]" id="trip_date" value="<?php
if(isset($_POST['trip_date']))
{
echo cleanStickyString($_POST['trip_date']);
}
我不确定的是 $_POST[trip_date] 是否实际上需要为 $_POST[trip_date[]],尽管这似乎会检查数组是否已设置。
任何正确方向的提示将不胜感激!老实说,我还无法测试它,因为我的队友还没有建立数据库,但因为它难倒了我丈夫,我想我应该立即尝试一下,看看是否有人有数据库他们可以分享的经验。 =/
谢谢您的宝贵时间。我知道你们都自愿花时间帮助别人,我很感激!
I'm a student in my last quarter of school working on a project. I'm using JQuery to allow the addition of form fields on the fly, so I have to use arrays for the name field so I can collect the information from potentiall multiple fields that are the same. I'd also like to make said form fields sticky. I've searched Google, searched stackoverflow and asked my veteran developer husband (should have seen the look on his face when I'd stumped him).
I am writing my code like this:
<input type="text" name="trip_date[]" id="trip_date" value="<?php
if(isset($_POST['trip_date']))
{
echo cleanStickyString($_POST['trip_date']);
}
What I'm unsure of, is if $_POST[trip_date] needs to actually be $_POST[trip_date[]], though it seems like that would check to see if the array was set.
Any hint in the right direction would be much appreciated! Honesty, I haven't been able to test it yet because my team mates haven't set up the database yet, but because it stumped my husband, I thought I'd get a jump on it and see if anyone out there had any experience they could share. =/
Thank you for your time. I know you all volunteer your time to help others out, it's appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定“粘性”是什么意思,但似乎您试图让 PHP 在提交表单后呈现使用 jQuery 添加的所有输入(及其值)。正确的?
试试这个:
Not sure what you mean by "sticky", but it seems you are trying to get PHP to render all inputs added with jQuery (and its values) after the form is submitted. Right?
Try this: