php - 提交表单后,我没有在数组中获得多个值
问题描述
当我单击Add More
Button 然后附加同一行时,当我提交表单时,我得到了输入字段的第一个值。product_name
我color_id
没有发现问题在哪里。
这是html代码:
<table class="table table-striped table-bordered text-center table-responsive">
<thead class="text-dark">
<tr>
<th>Product Name</th>
<th>Color</th>
@foreach($size_infos as $sizee)
<th>{{$sizee->size_name}}</th>
@endforeach
<th>Add More</th>
</tr>
</thead>
<form action={{url('product-purchase-process')}}" method="POST" enctype="multipart/form-data">
@csrf
<tbody class="add_item">
<tr>
<td width="20%">
<input class="form-control input typeahead" type="text" name="product_name[]" id="product_name" placeholder="Product Name" multiple='multiple'>
</td>
<td width="14%">
<select class="form-control input" name="color_id[]">
<option value="">--Select Color--</option>
@foreach($color_infos as $color)
<option value="{{$color->color_id}}">{{$color->color_name}}</option>
@endforeach
</select>
</td>
@foreach($size_infos as $size)
<td>
<div id="inputDiv">
<input type="hidden" name="size_id[]" value="{{$size->size_id}}" multiple='multiple'>
<input style="width:70px" class="from-control" type="text" name="product_quantity[]" multiple='multiple'>
</div>
</td>
@endforeach
<td width="10%">
<button type="button" id="add_more" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i></button>
</td>
</tr>
<tr>
</tr>
</tbody>
这是jquery代码:
<script type = "text/javascript" >
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).on('focus', "#product_name", function () {
$(this).autocomplete({
source: function (request, response) {
$.ajax({
url: "{{url('autocomplete')}}",
data: {
products: request.products
},
dataType: "json",
success: function (data) {
var resp = $.map(data, function (obj) {
// console.log(obj.product_name);
return obj.product_name;
});
response(resp);
}
});
},
minLength: 1
});
//color field and image field extend here
var htmlString = `<tr class="ree"><td width="20%"><input class="form-control input typeahead" type="text" name="product_name[]" id="product_name" placeholder="Product Name"></td><td width="14%"><select class="form-control input" name="color_id"><option value="">--Select Color--</option>@foreach($color_infos as $colorr)<option value="{{$colorr->color_id}}">{{$colorr->color_name}}</option>@endforeach</select></td>@foreach($size_infos as $sizeee)<td><div id="inputDiv"><input type="hidden" name="size_id[]" value="{{$sizeee->size_id}}"><input style="width:70px" class="from-control" type="text" name="product_quantity[]"></div></td>@endforeach<td width="10%"><button type="button" class="btn btn-danger btnRemove"><i class="fa fa-trash" aria-hidden="true"></i></button></td></tr>`;
$('#add_more').click(function () {
$('.add_item').append(htmlString); // end append
$('.ree .btnRemove').last().click(function () {
$(this).parent().last().remove();
}); // end click
}); // end click
}); </script>
解决方案
推荐阅读
- css - 我可以在 Avada 页面构建器中使用 Hooks 向标签添加一些属性吗?
- azure - 在 Azure Linux Web 应用程序上交换槽很慢
- python - 创建具有自引用类型提示的递归数据类
- c++ - 我可以明确指定哪个键盘可以用作 Qt 中的输入设备吗?
- entity-framework-6 - 在同一个表中查询部分和
- python - 有人可以解释这一行中的排序是如何进行的。我看到排序是使用 lambda 函数完成的
- python - 有什么方法可以将直方图 bin 之外的数据放入最外面的 bin 中?
- flutter - 如何使用 Flutter 读取 .docx 文件?
- git - 无法在 git 中执行 git pull 上游
- nest - 如何在nestjs中运行工作进程