如何从嵌套表单中收集数据数组
How to gather array of data from nested form
嗨,我正试图使用javascript让管理员输入产品的尺寸、袋子数量和纸箱数量。由于我不能使用嵌套表单,所以我在表单中使用javascript。我可以使用javascript实现它,但无法收集文本框中输入的所有数据。仅显示第一个条目。
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
<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
<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>
当我打印_r($_SESSION[myInputs_all])时,它显示
Array ( [0] => Array ( [0] => ujkopl [1] => jl[ [2] => uj [3] => juy ) ) Array
尝试这样的循环
<?php for($i=0;$i<count($_SESSION["myInputs_all"]);)?>
<tr> <td><?php echo $_SESSION["myInputs_all"][$i]['ItemDescription']; ?></td></tr>
"项目描述"是针对每个索引i打印的索引值。在您的代码中,"myInputs_all"似乎是会话值的数组。因此打印每个索引将是正确的方式。HTH
相关文章:
- 使用数据数组创建多个类似组件
- WebAudio API数据数组大小
- Jquery 循环一次或在数据数组中显示一次数据
- Cakephp 访问不在模型数据数组上的输入
- 使用来自 Ajax 响应的 JSON 数据数组
- Angular JS(离子)数据数组到$scope元素
- handontable:在不更改数据数组/对象的情况下隐藏某些列
- 如何使用for循环语句通过Ajax发送大数据数组
- 压缩 JS 中的数据数组
- 传递的参数D3提示回调是完整的数据数组
- 如何在数据数组的每次迭代中创建一个内容为“i+1”的新 HTML 元素
- 在 laravel 4 上使用循环将数据数组存储到单个数组中
- 为什么它说输入数据数组的格式不正确 jqchart.
- Javascript - 使用变量 RegExp 匹配数据数组中的多个关键字
- 尝试将数据数组设置为从视图调用函数后$scope
- 如何在 PHP 中创建 jqplot 数据数组
- 如何使用该数据数组从左向右移动画布
- 如何根据数字列从 Parse 中对数据数组进行排序
- 为什么 php json 响应不会将数据数组发送回 ajax jquery 请求
- 如何将内容添加到 JQuery Flot 图表数据数组工具提示