phpsymfony

Symfony 7 : flash message not showing


I’m writing here because someone may have already solved this problem:

Here’s my code:

$form = $forumService->handleDiscussionForm($request);

if ($form === "submitted") {
    $this->addFlash('success', 'Your discussion has been successfully created and must be validated by Parentela.');
    return $this->redirectToRoute('app_forum_thematique', ['slug' => $thematique->getSlug()]);
}

Test 1:

When I submit my form with this code, I am correctly redirected to the "app_forum_thematique" route, but the flash message does not display.

Test 2:

$form = $forumService->handleDiscussionForm($request);

if ($form === "submitted") {
    $this->addFlash('success', 'Your discussion has been successfully created and must be validated by Parentela.');
    dd("test");
    return $this->redirectToRoute('app_forum_thematique', ['slug' => $thematique->getSlug()]);
}

If I add a dd("test") and submit my form, the "test" displays. I then remove it from the code and refresh my page. At that point, the flash message displays, and I am correctly redirected.

Question is : why doesn’t this work without the manipulation with the dd("test")? Have you ever encountered this problem?

Thanks for your help :)


Solution

  • I got it.

    And that's strange, but maybe someone can explain it ?

    My probleme was because of turbo : When i add data-turbo="false" on my button, my flash message reappear.

    So it seems that without "data-turbo=false", turbo preload my "submit click", load the flash message and don't reload it when i do the real click, which is not really usefull :x