Skip to content
Chris Yates edited this page Nov 16, 2024 · 8 revisions

Wizard allows multi-page forms to be easily created and managed using a single controller action.

Using Wizard

Routing

Add A route for the Wizard in your routing config.

$routes = [
    Route::methods([Method::GET, Method::POST], '/wizard')
    // or Route::methods([Method::GET, Method::POST], '/wizard/{step:\w+}') for user-friendly URLs
        ->action([WizardController::class, 'wizard'])
        ->name('WizardStep'),
];

Action

Inject the Wizard into the action, initialise it, then call the Wizard's step() method.

Initialisation Methods

  • withAutoAdvance(bool) - optional - Determines which step Wizard redirects to if it has been sent back to an earlier step. If true Wizard will always redirect to the first unprocessed step, if false Wizard will redirect to the next step. Has no effect if ForwardOnly is true. Default true
  • withDefaultBranch(bool) - optional - Wizard will use the default (first) branch
  • withForwardOnly(bool) - optional - If true, Wizard can not return to an earlier step and will always redirect to the next step. Default false
  • withId(string) - optional if only one Wizard, required if more than one Wizard, Used by event handlers to decide if they should handle the event
  • withStepParameter(string) - optional - The route parameter in the step route. It is used to create user-friendly URLs; it has no other purpose. Example: if not given, the step URL will be something like '/wizard'. If given, the step URL will be something like '/wizard/step_1'.
  • withSteps(array) - required - the steps to process
  • withStepTimeout(int) - optional - Step timeout in seconds Default 0 - no step timeout
  • withSessionKey(string) - optional - The Wizard session key Default __'wizard'
public function wizard(ServerRequestInterface $request, WizardInterface $wizard): ResponseInterface
{
    return $wizard
        ->withId(self::class)
        ->withSteps(['step1', 'step2', 'step3'])
        ->step($request)
    ;
}

Clone this wiki locally