我想建立一个调查表。当我使用以下代码时,我只能看到包含 18 个问题(和答案字段)的表格的最后一个问题。
我不能使用集合,因为我的问卷会更复杂,有些问题有多个答案,有些问题是真/假,等等。我简化了代码以首先解决这个问题。
//Get question array collection
$questions = $questionnaire->getQuestions();
$formBuilderQuestionnaire = $this->createFormBuilder();
//Make a loop for each question
foreach($questions as $question)
{
//Create an answer form
$answer = new Answers($question, $evaluation);
$formBuilder = $this->createFormBuilder($answer);
//Add a answer text box with the question as label
$formBuilder->add('answerText', 'textarea', array(
'required' => false,
'label' => $question->getQuestionText()
));
$formBuilderQuestionnaire->add($formBuilder);
}
//Create the form
$form = $formBuilderQuestionnaire->getForm();
return $form->createView();
}