duanhai7274 2010-01-30 22:59
浏览 24
已采纳

JavaScript注入表单字段不会出现在POST数据中

I have a form that generates new input fields via JavaScript on click. the inputs are successfully added to the FORM with the desired naming convention.

<input type="text" name="util_name0" id="util_name0" value="" /><br/>
<input type="button" onClick="newUtil(this)" value="Add New" />

newUtil() adds:

<input type="text" name="util_name1" id="util_name1" value="" />

however after posting, print_r($_POST) only lists 'util_name0'.

Normally i'd paste some code, but that's all i really need to do at this point... form is in an include called from parent.php. Javascript is called in parent.php

JS:

function newUtil(el) {
    var newval = util_count++;
    $('#qty').attr('value', newval);
    $(el).before('-------------<br />
   <div class="newUtilField">
       <label for="util_type'+newval+'">Type (i.e. gas, electric...) '+newval+'</label><br />
       <input type="text" name="util_type'+newval+'" id="util_type'+newval+'" value="" /><br /><br />
       <label for="util_name'+newval+'">Company Name</label><br />
       <input type="text" name="util_name'+newval+'" id="util_name'+newval+'" value="" /><br /><br />
       <label for="util_number'+newval+'">Company Number</label><br />
       <input type="text" name="util_number'+newval+'" id="util_number'+newval+'" value="" />
   </div><br /><br />');
}
  • 写回答

3条回答 默认 最新

  • douzhuo6270 2010-01-31 02:45
    关注

    After execute the js code that adding the new field, inspect the new element using Firebug (in Firefox) or Web Inspector (in safari and google chrome). If the new field is outside the form tag, then it will not be included to form submit.

    If you can, please provide the structure of form and it's fields. Also, make sure that the page contain no other error, and the tag is well balanced, all open tag have been closed in the right place. Misplace closing tag might yield error and unexpected behaviour.

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

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致