Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How submit form in modal ? #11

Open
moreaul opened this issue Apr 8, 2022 · 0 comments
Open

How submit form in modal ? #11

moreaul opened this issue Apr 8, 2022 · 0 comments

Comments

@moreaul
Copy link

moreaul commented Apr 8, 2022

I integrate a form in the modal in order to create a new object but the validation of this one does not happen as agreed:
the object is not created and for a few seconds the redirect page is loaded in the modal.

Button on index.html.twig :

<a href="{{ path('category_new') }}" data-sideclick-modal-trigger>
            <i class="fa fa-plus-circle"></i> Créer une catégorie
        </a>

Here is my controller code:

/**
      * @Route("/new-category", name="category_new", methods={"GET", "POST"})
      */
     public function addCategory(Request $request): Response
     {
         $category = newCategory();

         $form = $this->createForm(CategoryType::class, $category);
         $form->handleRequest($request);

         if ($form->isSubmitted() && $form->isValid()) {
             $this->entityManager->persist($category);
             $this->entityManager->flush();

             return $this->redirectToRoute('stores_index');
         }

         return $this->renderForm('store/category_form.html.twig', [
             'category' => $category,
             'form' => $form,
         ]);
}

Here my category_form.html.twig :

<div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body">
                {{ form_start(form) }}
                {{ form_widget(form) }}
                <button class="btn">{{ button_label|default('Save') }}</button>
                {{ form_end(form) }}
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div><!-- /.modal-content -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant