简体   繁体   中英

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:

<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. I've confirmed the values are not posting (through print_r($_POST);) and through firebug.

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. Check it on the single php-page. I think problem is not in this script or this form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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