dounuo7954 2012-04-05 15:17
浏览 22
已采纳

动态添加的表单字段未显示在POSTed数据中

I'm using jQuery to add a form element. It appears on the page fine, with the correct value, but when I submit the form, the data doesn't show up on the PHP backend. I looked at Firebug's POST data and I don't see it in there either. The javascript I'm using to add the form element is:

$("#projectArray").append("<input type='text' name='data[Project][description]' value='"+projectDescription+"' id='test' />");

Has anyone run across anything like this? I've seem other posts but they seem to be typos and from what I can tell, I don't have any typos in this line.

Edit: As requested, here is the form code. I cut a lot of it out, as it is a pretty large form. If anyone wants the complete code, I can paste it.

<form action="/learningexperiences/add" id="LearningexperienceAddForm" method="post" accept-charset="utf-8">
    <div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>
    <div class="input text"><tr><td><label for="LearningexperienceSubjectarea">Subject Area</label>&nbsp;&nbsp;</td><td><input name="data[Learningexperience][subjectarea]" maxlength="50" type="text" id="LearningexperienceSubjectarea"/></td></tr>
...
    <tr><td>Active</td><td><div class="cbx"><input type="hidden" name="data[Learningexperience][active]" id="LearningexperienceActive_" value="0"/><input type="checkbox" name="data[Learningexperience][active]"  checked="checked" value="1" id="LearningexperienceActive"/></div></td></tr>

    <tr><td colspan="2" style="vertical-align:middle;"><div id="projectArray"></div></td></tr>

...
    <input type="hidden" name="data[Learningexperience][id]" id="LearningexperienceId"/><tr><td colspan="2" style="vertical-align:middle;">&nbsp;</td></tr>

</table>

<table id="buttonsTable">
<tr><td style="text-align:right;"><div style="margin-right:5px;"><div class="submit"><input  name="cancel" type="submit" value="Cancel"/></div></div></td>
<td><div class="submit"><input  type="submit" value="Save Record"/></div></form></td></tr>
</table>

Edit 2: I changed my append tag to append to the form element (#LearningexperienceAddForm). I don't know why, but it started working at that point.

  • 写回答

5条回答 默认 最新

  • douzhou7037 2012-04-06 13:42
    关注

    I changed my append tag to append to the form element (#LearningexperienceAddForm). I don't know why, but it started working at that point.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄