Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
How to Build Multi-step Forms in Drupal 8
Jul 07, 2015 @ 12:25:06

The SitePoint PHP blog has a post for the Drupal users out there showing you how to create multi-step forms in your application.

In this article, we are going to look at building a multistep form in Drupal 8. For brevity, the form will have only two steps in the shape of two completely separate forms. To persist values across these steps, we will use functionality provided by Drupal’s core for storing temporary and private data across multiple requests. In Drupal 7, a similar approach can be achieved using the cTools object cache. Alternatively, there is the option of persisting data through the $form_state array as illustrated in this tutorial.

They start by setting out what the end result will be - a simple two-page form with two fields each, allowing for navigation back and forth between the pages. They start with a base class defining requirements needed for both pages and setting up the necessary form structure. They walk through each part of this base class, explaining the functionality going along. With that in place they extend it with a "MultistepOneForm" and "MultistepTwoForm" classes extending the base and defining two fields on each.

tagged: tutorial drupal drupal8 multistep form

Link: http://www.sitepoint.com/how-to-build-multi-step-forms-in-drupal-8/

Henrik Bjørnskov's Blog:
Symfony2: How to do a Wizard (multistep form) with Doctrine2
Nov 03, 2011 @ 09:13:51

Henrik Bjørnskov has a new post with a technique you can use to combine Symfony2 and Doctrine2 to create a multi-step form (a wizard) without having to worry about lost user information between steps.

The easy ways is doing it with Javascript and just show/hide the correct fieldsets when needed. The downside with this approach is that the data is only saved and validated once at the end. So if the user reloads the page the entered information is gone. The other way is to have every Step in the Wizard being a seperate form and validate the data based on what step you are on and save the necessary fields.

For his method, he created a Manager class with a StepInterface that returns the correct field names, forms and template information to render. The interface code is included in the post as well as an example of it in use setting up the wizard object, making a report and getting the correct step information from the wizard.

tagged: wizard multistep form doctrine2 symfony2 framework

Link: