Search code examples
symfonysymfony-formssubmit-button

how to split long symfony form in multiple pages?


I want to create a form for an entity which has a many attributes. To ensure the ease of data entry, I want to split that form in multiple pages (for example 2 or 3 pages). Let's take the ad entity example:

  1. In page 1, the user will enter the ad text
  2. In page 2, the user will enter his contact
  3. In page 3, the user will provide the (X,Y) position of the ad

This split will require saving the available data (inserting in the database) in the 1st page before moving to the next page. Unfortunately, This is not possible due to constraints.

The question is: Is any documentations or any examples that solve this issue?

If no documentation is available, do you think it is better to split my entity in n entities in order to have one entity per page?

Thanks for you help.


Solution

  • You probably should use CraueFormFlowBundle. It provides facilities for building multi-step forms.

    You can create one form type for an entire flow, or one form type per step.

    It's very easy to setup. Everything is explained here.