【发布时间】:2018-04-17 16:01:46
【问题描述】:
我有问题列表,所有问题都在 foreach 循环中打印。我想使用复选框在数据库中存储一些问题 ID。
@foreach ($allquestion as $indexKey => $all )
<tr>
<th>{{$indexKey+1}}</th>
<th>{{substr($all->question,0,20)}} {{ strlen($all->question)>20
? "..." : ""}}</th>
<td>{{$all->option1}}</td>
<td>{{$all->option2}}</td>
<td>{{$all->option3}}</td>
<td>{{$all->option4}}</td>
<td>{{$all->answer}}</td>
<td>
<div class="form-check">
<input class="form-check-input big-checkbox"
name="present[]" type="checkbox" value="{{$all->id}}"
id="defaultCheck1">
</div>
</td>
</tr> @endforeach
我不知道我将提交按钮放在哪里以及如何从复选框中获取值到控制器中以保存数据。
更新
{!! Form::open(array('route' => 'addq', 'data-parsley-validate' => '',
'files' => true,'method'=>'post')) !!}
@foreach ($allquestion as $indexKey => $all )
<tr>
<th>{{$indexKey+1}}</th>
<th>{{substr($all->question,0,20)}} {{ strlen($all->question)>20 ? "..." : ""}}</th>
<td>{{$all->option1}}</td>
<td>{{$all->option2}}</td>
<td>{{$all->option3}}</td>
<td>{{$all->option4}}</td>
<td>{{$all->answer}}</td>
<td>
<div class="form-check">
<input type="checkbox" class="form-check-input big-checkbox"
name="checked[]" value="{{ $all->id }}">
</div>
</td>
</tr>
@endforeach
{{Form::submit('Create Test',['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
当我像这样放置按钮时,不会执行任何操作。
【问题讨论】: