Hi guys. I have this Symfony code where I am building a form with radio buttons. My problem is that when the user submits it’s choice this is not always passed to the twig template. Sometimes the data is passed sometimes is not. Why I am getting this inconsistency? Can someone help? Thanks
Here is my code:
public function playAction(Request $request){
$data = $this->getDbQuestion();
$questionData = $data[0];
$questionID = $questionData->getId();
dump($questionData);
$answerData = $data[1];
dump($answerData);
$form = $this->createFormBuilder($answerData)
->add('answers', EntityType::class, array(
'class' => 'QuizBundle:Answer',
'query_builder' => function (EntityRepository $er) use ($questionID) {
return $er->createQueryBuilder('a')
->where('a.question = :qID')
->setParameter('qID', $questionID);
},
'multiple'=>false,
'expanded'=>true,
'choice_label' => 'answer',
))
->add('Submit',SubmitType::class, array('label' => 'Send Answer'))
->getForm();
$form->handleRequest($request);
if($form->isSubmitted()) {
$formData = $form->get('answers')->getData();
return $this->render('QuizViews/correctAnswer.html.twig', array('ss' => $formData ));
}
return $this->render('QuizViews/playQuiz.html.twig', array('form' => $form->createView(),'question' => $questionData));
}
The dump is just to show the data I am getting from DB.