简体   繁体   English

动态表单未发布完整数组

[英]dynamic form not posting full array

I'm trying to give my users the ability to add multiple values, if needed. 我正在尝试让我的用户能够添加多个值(如果需要)。 I using the following JS form: 我使用以下JS形式:

<script type="text/javascript"> 
var counter = 1;
var limit = 3;
function addInput(divName){
   if (counter == limit)  {
      alert("You have reached the limit of adding " + counter + " inputs");
   }
   else {
      var newdiv = document.createElement('div');
      newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]' value=''>";
      document.getElementById(divName).appendChild(newdiv);
      counter++;
   }
}
</script>

The following form: 形式如下:

<form action="add.php" method="post" ENCTYPE="multipart/form-data">
<div id="dynamicInput">Entry 1<br><input type="text" name="myInputs[]"></div>
Enter the POC's number<br>
<input type="button" value="Add another POC" onClick="addInput('dynamicInput');">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>

If I fill in the first value as 123 and the second value as 124, once it posts to add.php, I only get the first value. 如果我将第一个值填写为123,将第二个值填写为124,则将其发布到add.php后,我只会得到第一个值。 I've confirmed the values are not posting (through print_r($_POST);) and through firebug. 我已经确认这些值没有通过Firebug发布(通过print_r($ _ POST);)。

Array ( [myInputs] => Array ( [0] => 123 )

Can anyone find why I'm losing the rest of the array? 谁能找到我为什么会丢失其余阵列的原因?

There is the form handler in your site, because array element [Submit] => Submit is losted too. 您的站点中有表单处理程序,因为数组元素[Submit] => Submit也丢失了。 Check it on the single php-page. 在单个php页面上检查它。 I think problem is not in this script or this form. 我认为问题不在此脚本或此形式中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM