Q: How to keep form data when browsing paginated output? I have a symfony form that contains a long list of items with checkboxes.  I have successfully made knp paginator work and now the form is split into pages.  However, when I move between pages I lose the checked/unchecked status of the checkboxes.  I am sure that this is probably quite easy but I cannot seem to work it out. I am not very experienced with php yet.
Here is my controller:
    /**
     * @Route("/addquestions/{quizid}", name="addquestions")
     */
    public function add(Request $request, PaginatorInterface $paginator, $quizid)
    {
        $repository = $this->getDoctrine()->getRepository(Quiz::class);
        $quiz = $repository->find($quizid);

        $repository = $this->getDoctrine()->getRepository(Question::class);
        $questions = $repository->findAll();

        // Paginate the results of the query
        $pagination = $paginator->paginate($questions, $request->query->getInt('page', 1), 3);

        $form = $this->createForm(AddQuizQuestionType::class, $quiz, ["pagination" => $pagination]);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $questions = $form->get('question')->getData();
            foreach ($questions as $question){
                $quizquestion = new QuizQuestion();
                $quizquestion->setQuestion($question);
                $quiz->addQuizQuestion($quizquestion);
            }
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($quiz);
            $entityManager->flush();
            return $this->redirectToRoute('homepage');
        }

        return $this->render('editquiz/addquestions.html.twig', [
            'form' => $form->createView(),
            'pagination' => $pagination,
        ]);
    }

And my form - it uses the paginated query to display the items with a check box.
class AddQuizQuestionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('question', EntityType::class, [
                'expanded' => true,
                'multiple' => true,
                'class' => Question::class,
                'mapped' => false,
                'choices' => $options['pagination'],
            ])
            ->add('submit', SubmitType::class, [
                'label' => 'Submit',
            ])
            ->setMethod('GET')
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Quiz::class,
            'pagination'    => null,
        ]);
    }
}

and my template - it renders the checkboxes with images from the database.
{% extends 'base.html.twig' %}
{% block title %}CreatequizController{% endblock %}
{% block body %}
<h1>Create Quiz</h1>
{{ form_start(form) }}
{% for question in form.question %}
<h5>Question {{ question.vars.value }}</h5>
<div class="border mb-5">
  <img src="{{ asset(question.vars.label) }}" alt=""/>
  <div class="pl-3">
    {{ form_widget(question) }}
  </div>
</div>
{% endfor %}
<div class="navigation">{{ knp_pagination_render(pagination) }}</div>
{{ form_end(form) }}
{% endblock %}

I would like it so that when I jump between pages the checkboxes that I have selected remain checked.
Thank you in advance,
Martyn
