简体   繁体   English

如何从嵌套表单中收集数据数组

[英]How to gather array of data from nested form

Hi Im trying to use javascript to allow admin to key in sizes,no of bags ,no of cartons available for a product. 嗨,我正在尝试使用JavaScript允许管理员键入尺寸,无袋,无纸箱的产品。 Since I can't use nested forms thus I use javascript inside form.I can achieve it using javascript but unable to gather all the data entered inside the textboxes.Only the very first entry displays. 由于无法使用嵌套表单,因此我在表单内部使用了javascript。我可以使用javascript实现它,但无法收集在文本框中输入的所有数据,仅显示第一个条目。

Php to display the data entered PHP显示输入的数据

 $_SESSION['myInputs_all'][]=array($_POST["myInputs_d"],$_POST["myInputs_d1"],$_POST["myInputs_bags"],$_POST["myInputs_carton"]);
 print_r($_SESSION['myInputs_all']);
foreach ( $_SESSION['myInputs_all'] as $eachInput) 
{
     echo $eachInput . "<br>";

}

HTML 的HTML

            <tr>
                <th>Size D(mm)</th>
                <th>Size D1(mm)</th>
                <th>No of Bags</th>
                <th>No of Carton</th>
                </tr>   

               <div id="dynamicInput">


         <tr><td> Entry 1</td></tr>
         <tr>
          <td><input type="text" name="myInputs_d" size='5'>
          <input type="text" name="myInputs_d1" size='5'>
          <input type="text" name="myInputs_bags" size='5'>
          <input type="text" name="myInputs_carton" size='5'></td>
         </tr>
     </div>
     <tr>
     <td>
     <input type="button" value="Add another text input"  name="myInputs[]" onClick="addInput('dynamicInput');">

                                                         </td>  
                                                        </tr>

javascript javascript

<script>
var counter = 1;
var limit = 10;
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) + " <input type='text' name='myInputs_d[]' size='5'><input type='text' name='myInputs_d1[]' size='5'><input type='text' name='myInputs_bags[]' size='5'><input type='text' name='myInputs_carton[]' size='5'>";
          document.getElementById(divName).appendChild(newdiv);

          counter++;
     }
}
</script>

When I print_r($_SESSION[myInputs_all]) it shows 当我print_r($ _ SESSION [myInputs_all])时,它显示

Array ( [0] => Array ( [0] => ujkopl [1] => jl[ [2] => uj [3] => juy ) ) Array

try loop like this 试试这样的循环

 <?php for($i=0;$i<count($_SESSION["myInputs_all"]);)?>
<tr> <td><?php echo $_SESSION["myInputs_all"][$i]['ItemDescription']; ?></td></tr>

"item description" is the index value that would be printed against each index i. “项目描述”是将针对每个索引i打印的索引值。 in your code "myInputs_all" seems to be the array of session values. 在您的代码“ myInputs_all”中似乎是会话值的数组。 so printing each index will be the exact way.HTH 因此打印每个索引将是准确的方法。

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

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