0

I have an issue trying to render a controller which returns a template with formView.

I understood about the sub-request, but I am having difficult time to show any kind of errors.

I think the problem is that after it sees the form is invalid it redirectsToRoute and it looses the POST Request.

If I don't say redirectTo it just renders the view.

base.html.twig

 {{ render(controller('AppBundle:Utility:renderSignUpWizard'), {request: app.request}) }}

Utility Controller

   /**
     * @Route("/registration/wizard/", name="registration.wizard")
     */
    public function renderSignUpWizardAction(Request $request)
    {
        /** @var $user User */
        $user = $this->getUser();

        $form = $this->createForm(SignUpWizardType::class, $user);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid())
        {
            // save changes to user
            $this->persistAndSave($user);

            // redirect to profile
            return $this->redirectToRoute('profile');
        }
        else if($form->isSubmitted() && !$form->isValid())
        {
            return $this->redirectToRoute('home');
        }

        return $this->render('partials/signup-wizard.html.twig', array
        (
            'form' => $form->createView(),
        ));
    }

1 Answer 1

1

If you could show the twig file where you put the form I could have given a clearer answer. Check the twig file you tell your controller to render and add the following:

Simple way to generate your form(doesn't include errors):

{{ form_start(form) }}
{{ form_widget(form) }
{{ form_end(form) }}

Add:

{{ form_errors(form) }}

if you want erors for a specific field:

{{ form_errors(form.name) }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.