3
私は自分のページの一つに簡単なマルチチェック回答フォームを持っています。すべてのフィールドが必須で、検証が完了して正しいことを確認しています。複数のエラーメッセージを確認中に一度だけ表示する
エラーメッセージが返ってきたら、どちらの答えが間違っているかは言いたくありません。しかし、どの具体的な質問が記入されていないのかを教えても問題ありません。このことを考えると
は、私はそうのように、私のバリデータを構築しました:
$validator = Validator::make($request->all(), [
'multi1' => 'required|in:b',
'multi2' => 'required|in:a',
'multi3' => 'required|in:c',
'multi4' => 'required|in:b',
'multi5' => 'required|in:c',
'multi6' => 'required|in:a',
'multi7' => 'required|in:c',
'multi8' => 'required|in:c',
'multi9' => 'required|in:a',
'multi10' => 'required|in:b',
], [
'multi1.required' => 'The first question is empty!',
'multi2.required' => 'The second question is empty!',
'multi3.required' => 'The third question is empty!',
'multi4.required' => 'The fourth question is empty!',
'multi5.required' => 'The fifth question is empty!',
'multi6.required' => 'The sixth question is empty!',
'multi7.required' => 'The seventh question is empty!',
'multi8.required' => 'The eighth question is empty!',
'multi9.required' => 'The ninth question is empty!',
'multi10.required' => 'The tenth question is empty!',
'multi1.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi2.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi3.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi4.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi5.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi6.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi7.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi8.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi9.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
'multi10.in' => 'At least one of your answers was incorrect. Please review them and resubmit.',
]);
if ($validator->fails()) {
return redirect('/application/multichoice')
->withErrors($validator)
->withInput();
}
これで唯一の問題は、質問の1つ以上が正しくない場合は、その後、同じエラーメッセージ、At least one of your answers was incorrect. Please review them and resubmit.
が、繰り返されていることです複数回。
私はそうのようにページ上でそれをプリントアウトしています:
@if (count($errors) > 0)
<div class="alert alert-danger">
<p><b>There are some errors with your answers:</b></p>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
が起きてからこれを防ぐために、または一度だけ、それをプリントアウトする簡単な方法はありますか?
私は{{ 'に' $のprev'の宣言を変更する必要がありました - - */$ prev = null;/* - }} 'しかし、これ以外は完全に機能しました! – James