title: Symfony 4 modal form
body: <p>I have a list of cars, each car has a button, and pressing the button allows me to access a modal form to write a ticket for that specific car. Example: <a href="https://imgur.com/a/t82H9UT" rel="nofollow noreferrer">https://imgur.com/a/t82H9UT</a></p>
  
  <p>The problem is that I'm having some problems integrating the modal and the form inside my twig.</p>
  
  <p>The form I'm supposed to fill has 4 inputs alltogether. the first 2 are supposed to get pre-filled by data passed from the car related to the pressed button, the rest I can fill myself. But I don't know how to pass these informations from the twig to the form.</p>
  
  <p><strong>What I did so far :</strong></p>
  
  <ul>
  <li>I have my list, my button in an index.html.twig file, and I have my form inside a model in a separate twig called modal.html.twig, I also made a controller.</li>
  </ul>
  
  <p><strong>Problem :</strong>
  Pressing the button won't show anything.</p>
  
  <p><strong>My code :</strong></p>
  
  <p>index.html.twig</p>
  
  <pre><code>{% block title %}Parking index{% endblock %}
  
  {% block body %}
  
  
    &lt;table id="file_export" class="table table-striped table-bordered"&gt;
      &lt;tbody&gt;
        {% for voitures in voiture %}            
            &lt;tr&gt;
              &lt;td&gt;
                {{ voitures.matricule }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ voitures.parking.libelle }}         
              &lt;/td&gt;
              &lt;td&gt;
               &lt;span class="timer" data-expires="{{ voitures.getExpiresAt() }}"&gt;&lt;/span&gt;
              &lt;/td&gt;
              &lt;td&gt;
              &lt;button type="button" class="btn btn-dark" href="{{ path('new_ticket', {'id': voitures.id},{'parking': voitures.parking.id}) }}" data-toggle="modal" data-target="#createmodel" data-whatever="{{ voitures.id }}"&gt;ticket&lt;/button&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          {% endif %}
       {% endfor %}
  </code></pre>
  
  <p>My modal.html.twig form:</p>
  
  <pre><code>&lt;div class="modal fade" id="createmodel" tabindex="-1" role="dialog" aria-labelledby="createModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog" role="document"&gt;
          &lt;div class="modal-content"&gt;
              &lt;form&gt;
                     &lt;div class="modal-header"&gt;
                      &lt;h5 class="modal-title" id="createModalLabel"&gt;&lt;i class="ti-marker-alt m-r-10"&gt;&lt;/i&gt; ticket for:&lt;/h5&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                      &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                     &lt;/div&gt;
                     &lt;div class="modal-body"&gt;
                      {{ form_start(form) }}
  
                          {{ form_row(form.Matricule, { 'label': 'Matricule' }) }}
                          {{ form_row(form.Parking, { 'label': 'Matricule' }) }}
                          {{ form_row(form.Date, { 'label': 'Date' }) }}
                          {{ form_row(form.montant, { 'label': 'Montant' }) }}
  
                          &lt;button class="btn"&gt;{{ button_label|default('Add') }}&lt;/button&gt;
                      {{ form_end(form) }}
  
  
  
                     &lt;/div&gt;
                     &lt;div class="modal-footer"&gt;
                          &lt;button type="button" class="btn btn-secondary" data-dismiss="modal"&gt;Close&lt;/button&gt;
                          &lt;button type="submit" class="btn btn-success"&gt;&lt;i class="ti-save"&gt;&lt;/i&gt; Save&lt;/button&gt;
                     &lt;/div&gt;
              &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and finally my controller (which doesn't work)</p>
  
  <pre><code>    /**
       * @Route("/ticket", name="new_ticket", methods={"GET","POST"})
       */
      public function newTicket(Request $request): Response
      {
          $ticket = new Ticket();
          $form = $this-&gt;createForm(TicketType::class, $ticket);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $this-&gt;addFlash('success','ammende added !');
  
              $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
              $entityManager-&gt;persist($ticket);
              $entityManager-&gt;flush();
  
              return $this-&gt;redirectToRoute('agent');
          }
  
          return $this-&gt;render('Agent/modal.html.twig', [
              'ticket' =&gt; $ticket,
              'form' =&gt; $form-&gt;createView(),
          ]);
      }
  </code></pre>
  
  <p><strong>This is the solution I found :</strong>
  I used render to integrate the form inside my index, it's not perfect but it works:</p>
  
  <pre><code>         {{render(controller('App\\Controller\\AgentController:newTask')) }}
  </code></pre>