user742736
user742736

Reputation: 2729

Symfony form validation on redirected page

Is it possible to display the form error on a redirected page instead of a rendered page?

I have 2 forms on 1 page each submitting to their own actions. If form 1 is not valid it will skip if($form->isValid()) and go straight to render which will then display the form errors. The 'render` for this actions only displays form 1).

The issue with this is I would like it to redirect back to the original page where I have both of the forms but still display the form errors.

Upvotes: 1

Views: 713

Answers (1)

Marcel Burkhard
Marcel Burkhard

Reputation: 3523

I don't know any easy way to do this, so I give you an idea how this could be done the "hard" way:

  1. Serialize the validated form using JMSSerializerBundle

  2. Set the serialized form as flashbag message

  3. Redirect

  4. Check for the form in the flashbag, unserialize, show the errors of both.

Upvotes: 1

Related Questions