Answer the question
In order to leave comments, you need to log in
How to write to the database the value of the radiobutton if it is not selected?
there is a form for adding a question with multiple answers. radiobutton indicates the correct / incorrect answer
form of the question:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('text', TextType::class, [
'label' => 'Question'
])
->add('answers', CollectionType::class, [
'entry_type' => AnswerType::class,
'label' => false,
'by_reference' => false,
'allow_add' => true,
'allow_delete' =>true,
])
->add('save', SubmitType::class, [
'attr' => [
'class' => 'btn btn-success'
]
])
;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('is_true', RadioType::class)
->add('text', TextType::class)
;
}
public function addQuestion(Request $request)
{
$forRender = parent::renderDefault();
$forRender['title'] = 'Add Question';
$em = $this->getDoctrine()->getManager();
$question = new Question();
$form = $this->createForm(QuestionType::class, $question);
$form->handleRequest($request);
if($form->isSubmitted()){
$em->persist($question);
$em->flush();
$this->addFlash('notification', 'Question added');
return $this->redirect($this->generateUrl("question"));
}
$forRender['form'] = $form->createView();
return $this->render('admin/createquestion.html.twig', $forRender);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question