Community Documentation

Multi-step forms

Last updated June 12, 2012. Created by blueminds on May 28, 2012.
Log in to edit this page.

<< mforms project page

Installation and configuration

Mforms is a library, so by itself it does not provide any functionality (besides the real-life examples in the mforms example module). Therefore there is no configuration or installation besides enabling the module in the module list.

Basic usage

Included module mforms_example contains several real life examples that are documented in code. To find out what it does visit /mforms page after you enable mforms_example module.

Mforms architecture

For faster dive into mforms here is the basic architecture:

Prerequisites

STORE_KEY - not just identifies the storage slot for submitted values, it represents the identifier of whole multi-step form implementation.

Steps file - The file where individual form steps with their validate and submit callbacks reside. See mforms_example/mforms/mforms_example.session_store_example.inc for demonstration. This file must be named in the following pattern: MODULE_NAME.STORE_KEY.inc and placed in "mforms" directory of the module in which you are implementing the multi step form.

Store object - MformsIstore implementation responsible for storing submitted values and internal mforms data needed to control the stepping process.

Steps object - it is aware of all steps, current step, next step and previous step.

Controls object - the UI control object. It controls the form buttons.

Mforms initialization

Initialization process consists of instantiation of store, steps and controls objects and calling mforms_init_module() function into which you pass these instantiated objects. You can do this in a Drupal page callback followed by call of drupal_get_form(). However this approach will not allow you to handle ajax calls.

The proper way is to implement hook_STORE_KEY_mforms_init() and
within this hook implementation do all initialization - see mforms_example.module, function mforms_example_fs_store_example_mforms_init().

Drupal form callbacks

The form lifecycle is handeled by Drupal. Therefore there must be regular form callbacks: FORM_ID(), FORM_ID_validate() and FORM_ID_sbumit(). Inside these mforms takes over as can be seen in the mforms_example.pages.inc, i.e. functions mforms_example_fs_form[validate, submit]().

Page status

Needs updating

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Level
Beginner, Intermediate, Advanced
Audience
Programmers
Keywords
form api, multi step form

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here