Open gremo opened 1 year ago
Did you find a solution?
Thanks to https://github.com/craue/CraueFormFlowBundle/issues/221 I think I've found a working solution:
<?php
namespace App\Controller;
use App\Form\TherapyRequestFlow;
use App\Form\TherapyRequestModel;
use Craue\FormFlowBundle\Util\FormFlowUtil;
use Symfony\Bridge\Twig\Attribute\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
class TestController extends AbstractController
{
#[Route('/test', name: 'app_test')]
#[Template('test/index.html.twig')]
public function test(TherapyRequestFlow $flow, FormFlowUtil $utils, Request $request): RedirectResponse|array
{
$model = new TherapyRequestModel();
$flow->bind($model);
$form = $submittedForm = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if (!$flow->nextStep()) {
$flow->reset();
dd($model);
}
$form = $flow->createForm();
}
if ($flow->redirectAfterSubmit($submittedForm)) { // IMPORTANT: do not use $form
return $this->redirectToRoute(
$request->attributes->get('_route'),
$utils->addRouteParameters(
[
...$request->query->all(),
...$request->attributes->get('_route_params'),
],
$flow,
)
);
}
return [
'form' => $form,
'flow' => $flow,
];
}
}
Here is my controller. I'm trying to make the "redirect after submit" option work:
http://localhost/?instance=eo-6lVKSna&step=2
)Am I'm doing something wrong in my controller?