diff --git a/src/Controller/ItemController.php b/src/Controller/ItemController.php index f432297953c5e9f49397c6ca72926458b5d785d5..560ed7c045f454416f9e02708f700735735e07b3 100644 --- a/src/Controller/ItemController.php +++ b/src/Controller/ItemController.php @@ -94,11 +94,16 @@ final class ItemController extends AbstractController #[Route('/{id}', name: 'app_item_delete', methods: ['POST'])] public function delete(Request $request, Item $item, EntityManagerInterface $entityManager): Response { - if ($this->isCsrfTokenValid('delete'.$item->getId(), $request->getPayload()->getString('_token'))) { + $wishlistId = $item->getWishlist()->getId(); + + if ($this->isCsrfTokenValid('delete' . $item->getId(), $request->request->get('_token'))) { $entityManager->remove($item); $entityManager->flush(); } - - return $this->redirectToRoute('app_item_index', [], Response::HTTP_SEE_OTHER); + + return $this->redirectToRoute('app_wishlist_show', [ + 'id' => $wishlistId + ]); } + } \ No newline at end of file diff --git a/templates/wishlist/show.html.twig b/templates/wishlist/show.html.twig index c97787145c47a587fa0e282b279639ab60c0408f..8061f694fffb47bbd6980bf437f610fcf67aca99 100644 --- a/templates/wishlist/show.html.twig +++ b/templates/wishlist/show.html.twig @@ -185,7 +185,10 @@ <button class="action-btn" onclick="window.open('{{ item.url }}', '_blank')">🛒</button> {% endif %} <button class="action-btn" onclick="window.location.href='{{ path('app_item_edit', {'id': item.id}) }}'">✏️</button> - <button class="action-btn delete-btn" data-delete-url="{{ path('app_item_delete', {'id': item.id}) }}">🗑️</button> + <form method="post" action="{{ path('app_item_delete', {'id': item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');" style="display:inline;"> + <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}"> + <button class="action-btn" title="Delete">🗑️</button> + </form> </div> </div> </li> @@ -208,7 +211,10 @@ <button class="action-btn" onclick="window.open('{{ item.url }}', '_blank')">🛒</button> {% endif %} <button class="action-btn" onclick="window.location.href='{{ path('app_item_edit', {'id': item.id}) }}'">✏️</button> - <button class="action-btn delete-btn" data-delete-url="{{ path('app_item_delete', {'id': item.id}) }}">🗑️</button> + <form method="post" action="{{ path('app_item_delete', {'id': item.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');" style="display:inline;"> + <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}"> + <button class="action-btn" title="Delete">🗑️</button> + </form> </div> </div> </li>