lekoala/silverstripe-multi-step-form

Multi step forms for SilverStripe

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-master 2021-09-14 15:35 UTC

This package is auto-updated.

Last update: 2022-05-14 17:08:26 UTC


README

Build Status scrutinizer Code coverage

Intro

A simple alternative to multiform

This module does not require storage in the back end and provide a somewhat easier DX.

How it works

Each step of your form should be named the same.

  • MyFormStep1
  • MyFormStep2
  • ...

They should all extends the base MultiStepForm class and implements the following abstract methods:

  • buildFields : returns a field list
  • getStepTitle : get the step title
class MyFormStep1 extends MultiStepForm
{
    public static function getStepTitle()
    {
        return 'My Step';
    }

    public function buildFields()
    {
        $fields = new FieldList();
        return $fields;
    }
}

In your controller, you declare a form like this:

private static $allowed_actions = array(
    'MyForm'
);

public function MyForm()
{
    $class = MyFormStep1::classForCurrentStep($this);
    return new $class($this);
}

Template helpers

You can display the steps using

$MyForm.DisplaySteps

This relies on some default styles that are added by default. You can disable styles and edit custom classes with:

LeKoala\MultiStepForm\MultiStepForm:
  include_css: true
  class_active: 'current bg-primary text-white'
  class_inactive: 'link'
  class_completed: 'msf-completed bg-primary text-white'
  class_not_completed: 'msf-not-completed bg-light text-muted'

TODO

  • Doc
  • Tests

Compatibility

Tested with 4.6 but should work on any ^4.4 projects

Maintainer

LeKoala - thomas@lekoala.be