我想知道如何将几个复选框的值作为数组从视图传递到控制器。这是我的代码:
我的观点:
@extends('layouts.master')
@section('content')
<?php
$count = 1;
?>
{{ Form::open(array('method' => 'POST', 'action' => array('createQuizController@addQuestion'), 'id' => 'add_question')) }}
<div class="col-lg-10 col-lg-offset-1">
<div class="table-responsive" id="question_table">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ردیف</th>
<th>عنوان سوال</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($result as $quiz)
<tr>
<td align="center" width="100px">
<?php echo $count++; ?>
</td>
<td align="center" width="200px">{{ $quiz->title }}</td>
<td align="center" width="200px"><input type="checkbox" name="select_question[]" id="counter[]" value="{{ $quiz->lesson_id }}"></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
{{ Form::submit('افزودن', ['class' => 'btn btn-primary']) }}
{{ Form::close() }}
<input type="text" id="count-checked" name="count-checked">
@stop
我想张贴复选框的值;$quiz->lesson_id
作为我的控制器方法的数组addQuestion。
您就快到了。我相信下面的构造将为您生成数组,其中每个复选框都有正确的ID集。
<input type="checkbox" name="select_question[{{ $quiz->lesson_id }}]" id="counter_{{ $quiz->lesson_id }}">