Symfony form submit button not working

2019-09-16 13:25发布

问题:

I'm trying to submit a form which is supposed to deactivate several documents. When hitting the "Submit" button nothing happens. Here is my twig file:

{% block content %}
{{ form_start(form) }}
 {{ form(form.documentlist) }}
{{ form_end(form) }}

<p>
  <div class="row">
    <button type="submit">Submit</button>
  </div>
{% endblock content %}

{% block javascripts %}
{{ parent() }}

<script src="{{ asset('js/bootstrap-multiselect.js') }}"></script>
<script>

makeMultiselectDropdown('#{{ form.vars.name }}_documentlist', 'Select Document');
</script>
<script type="text/javascript">
$(document).ready(function() {
  $('#{{ form.vars.name }}_documentlist').change(function() {
    var docId = $('#{{ form.vars.name }}_documentlist').val();
    $.ajax({
      type: "POST",
      data: {'id': docId},
    });
  });
});
</script>

{% endblock %}

and my Controller function:

  /**
  * @Route("/document/bulkdeactivate", name="documentBundle_document_bulkDeactivate")
  * @Template()
  */
  public function bulkDeactivateAction(Request $request) {

      $em = $this->getDoctrine()->getManager();
      $selected_documents = $request->request->all();

      $form = $this->createForm(DocumentDeactivationType::class);
      $form->handleRequest($request);

      if ($form->isValid() && $form->isSubmitted()) {
        foreach($selected_documents as $document) {
        $documentR = json_decode(json_encode($document), true);
        dump($documentR);
        for($i=0; $i<count($documentR); $i++){
          $doc = $em->getRepository('DocumentBundle:Document')->findOneById($documentR[$i]);
          dump($doc);
          $document->setActive(false);
          $em->persist($document);
          $em->flush();
        }
      }

            $this->addFlash(
            'success',
            'The document has been deactivated!'
            );
            return $this->redirectToRoute('documentBundle_document_list');
            }

          return $this->render('DocumentBundle:Panels:ActivationPanel.html.twig', array(
            'form' => $form->createView(),
          ));
}

I looked in the console while hitting "Submit" and it says

Uncaught TypeError: Cannot set property 'href' of null
at window.onload (bulkdeactivate:257)

which is the line that renders the twig template. I don't know if this has anything to do with my problem, just wanted to let you know as much as I know!

Any help would be appreciated!