Hi,
I've a form with dynamic questions, like this:
{{ form_ajax('onSend') }}
{% for question in chapter.questions %}
[fieldset]
[legend]{{ question.question }}[/legend]
{% for answer in question.answers %}
[label]
[input type="radio" name="question-{{ question.id }}" value="{{ answer.id }}"] {{ answer.answer }}
[/label]
{% endfor %}
[/fieldset]
{% endfor %}
[button type="submit"]Done[/button]
{{ form_close() }}
I've one chapter, contains its questions (not same according to the chapters), each question contains many answers (display as button inputs).
How I can get in my component class the dynamics inputs question-{{ question.id }}? I would like return an 'required' error message if no answer.
I tried...
$questions = Input::all();
foreach ($questions as $question => $answer) {
$validator = Validator::make(
[$question => $answer],
[$question => 'required'],
['required' => 'You must have select an answer!']
);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
}
How I can do that? Thanks.
Last updated