我有一个问题表。它通过单选按钮具有许多问题和问题选项。问题来自数据库循环,所以我为问题答案创建了5个无线电输入。完成该过程后,我会将所有选定的数据发送到数据库,但无法为每个问题选择答案。所有无线电名称都相同,以捕获控制器端每个答案的值。
我的模板如下;
{!! Form::open(['action'=>['HomeController@postSaveQuestionResult', $subject->id], 'method'=>'post']) !!}
@foreach($questions as $question)
<div style="padding:10px;border:1px solid #dedede;" id="answer-radio{{$question->id}}">
<p>Question #{{$question->id}}</p>
<p>{!! $question->question!!}</p>
<div class="funkyradio">
<div class="funkyradio-success">
<input type="radio" name="option" id="f-q-{{$question->id}}" value="1"/>
<label for="f-q-{{$question->id}}">{{$question->option1}}</label>
</div>
<div class="funkyradio-success">
<input type="radio" name="option" id="s-q-{{$question->id}}" value="2"/>
<label for="s-q-{{$question->id}}">{{$question->option2}}</label>
</div>
<div class="funkyradio-success">
<input type="radio" name="option" id="t-q-{{$question->id}}" value="3"/>
<label for="t-q-{{$question->id}}">{{$question->option3}}</label>
</div>
<div class="funkyradio-success">
<input type="radio" name="option" id="f-q-{{$question->id}}" value="4"/>
<label for="f-q-{{$question->id}}">{{$question->option4}}</label>
</div>
<div class="funkyradio-success">
<input type="radio" name="option" id="fi-q-{{$question->id}}" value="5"/>
<label for="fi-q-{{$question->id}}">{{$question->option5}}</label>
</div>
</div>
</div>
@endforeach