I am using Symfony 3 framework, and I need to create a form that will display a quiz question, and image and four possible answers as radio buttons. So far I have created the fields id,question and image that are mapped to my entity fields from my database but having problem with the radio buttons. Bellow is what I have so far.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id',HiddenType::class)
->add('image',TextType::class)
->add('question',TextType::class)
->add('Options to choose',ChoiceType::class,
array('choices' => array(
'answer1' => '1',
'answer2' => '2',
'answer3' => '3',
'answer4' => '4'),
'choices_as_values' => true,'multiple'=>false,'expanded'=>true))
->add('Submit',SubmitType::class);
}
My problem are the following:
->add('Options to choose' I cannot have this, because Symfony is trying to find methods in my entity class. Also bellow 'answer1' => '1' is not getting the data from the database. How can I pull the data from the database and display it for each radio buttons. How can I solve this issues and have 4 radio buttons that display the 4 database options. Thanks for the help.