Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure if I've understood your question correctly but maybe this could help.</p> <p>From what I see you're building the form(for questions) but you're not using it anywhere! The easiest way is to pass the questions(in your case $user->getQuestions() ) to the MyFormType and the add all the questions inside of the type.</p> <p>So it would look like something like this</p> <pre><code>$this-&gt;createForm(new MyFormType($user-&gt;getQuestions()), array('User' =&gt; $user)); </code></pre> <p>And inside your type</p> <pre><code>protected $questions; public function __construct($questions) { $this-&gt;questions = $questions; } protected $questions; public function __construct($questions) { $this-&gt;questions = $questions; } public function buildForm(FormBuilderInterface $builder, array $options) { foreach ($this-&gt;questions as $question) { $options = array(); foreach ($question-&gt;getOptions() as $option) { $options[$option-&gt;getId()] = $option-&gt;getOptionText(); $optionEntities[$option-&gt;getId()] = $option; } $builder-&gt;add('question_'. $question-&gt;getId(), 'choice', array( 'label' =&gt; $question-&gt;getQuestionText(), 'expanded' =&gt; $question-&gt;getExpanded(), 'multiple' =&gt; $question-&gt;getMultiple(), 'choices' =&gt; $options )); } } </code></pre> <p><strong>Edit 1</strong></p> <p>Why don't you try the following? </p> <p>Add the method setQuestionnaire in User and create a type called QuestionnaireType which is responsible to create the whole questionnaire In the UserType(sorry for the wrong names) add the QuestionnaireType as an embedded form Once the user submits the data and you call the bind symfony will pass the whole questionnaire object to the created method so you can iterate over it and save the user's aswers!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload