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 @ 17: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/


Trending Topics: