lexal / symfony-stepped-form
Symfony Stepped Form Bundle.
Package info
github.com/lexalium/symfony-stepped-form
Type:symfony-bundle
pkg:composer/lexal/symfony-stepped-form
Requires
- php: >=8.2
- lexal/http-stepped-form: ^4.0
- symfony/config: ^6.4 || ^7.4 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.4 || ^8.0
- symfony/event-dispatcher-contracts: ^3.7
- symfony/http-foundation: ^6.4.41 || ^7.4.13 || ^8.0.13
- symfony/http-kernel: ^6.4 || ^7.4.12 || ^8.0.12
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0.0
- infection/infection: >=0.32.6
- matthiasnoback/symfony-config-test: ^6.2
- matthiasnoback/symfony-dependency-injection-test: ^6.3
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^10.5.62
- roave/security-advisories: dev-latest
- symfony/twig-bundle: ^7.4
- symfony/yaml: ^7.4.15
- webimpress/coding-standard: ^1.4
Suggests
- symfony/event-dispatcher: Required to use Symfony Dispatcher as form Event Dispatcher (^6.4 || ^7.4 || ^8.0).
- symfony/twig-bundle: Required to use Twig as response renderer (^6.4 || ^7.4 || ^8.0).
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-01 18:24:21 UTC
README
The package is based on the HTTP Stepped Form and built for a Symfony framework.
Table of Contents
Requirements
- PHP: >=8.2
- Symfony: ^6.4 || ^7.4 || ^8.0
Installation
Via Composer
composer require lexal/symfony-stepped-form
Configuration
Register the bundle in config/bundles.php if not using Symfony Flex, and create config/packages/stepped_form.yaml for configuration options (renderer, redirector, event_dispatcher, exception_normalizers, and forms).
Example (manual bundles.php registration):
<?php return [ Lexal\SymfonySteppedForm\SteppedFormBundle::class => ['all' => true], ];
Example:
stepped_form: renderer: Lexal\SymfonySteppedForm\Renderer\Renderer redirector: Lexal\SymfonySteppedForm\Routing\Routing event_dispatcher: Lexal\SymfonySteppedForm\Event\Dispatcher\EventDispatcher forms: customer_create: form_builder: Lexal\SymfonySteppedForm\CreateFormBuilder form_settings: Lexal\SymfonySteppedForm\CreateFormSettings storage: class: Lexal\SymfonySteppedForm\Storage\SessionStorage arguments: { $namespace: 'customer-create' } session_key_storage: class: Lexal\SymfonySteppedForm\Storage\SessionSessionKeyStorage arguments: { $namespace: 'customer-create' } customer_edit: steps: first: Lexal\SymfonySteppedForm\Step\Step1 second: Lexal\SymfonySteppedForm\Step\Step2 form_settings: Lexal\SymfonySteppedForm\EditFormSettings storage: Lexal\SymfonySteppedForm\Storage\SessionStorage session_key_storage: Lexal\SymfonySteppedForm\Storage\SessionSessionKeyStorage
Where:
renderer- contains Renderer class or service alias that translates step's template definition into the response. Must implementLexal\HttpSteppedForm\Renderer\RendererInterface;redirector- contains Redirector class or service alias that redirects user between form steps. Must implementLexal\HttpSteppedForm\Routing\RedirectorInterface;event_dispatcher- contains Event Dispatcher class or service alias that dispatches form events. Must implementLexal\SteppedForm\EventDispatcher\EventDispatcherInterface;forms- contains form definitions. Key is the form name. Form is available in the Symfony container asstepped_form.form.<form_name>. When only one form registered, it is available via interfaceLexal\SteppedForm\SteppedFormInterface. Form definition contains:form_builder(required whenstepsis not provided) - contains FormBuilder class or service alias that builds form (only when it has dynamic steps). Must implementLexal\SteppedForm\FormBuilder\FormBuilderInterface;steps(required whenform_builderis not provided) - contains an array of step class or service aliases that implementsLexal\SteppedForm\Step\StepInterface(only when it has static steps);form_settings- contains FormSettings class or service alias that provides form settings. Must implementLexal\SteppedForm\FormSettings\FormSettingsInterface;storage- contains Storage class or service alias that provides form storage. Must implementLexal\SteppedForm\Storage\StorageInterface;session_key_storage(optional) - class or service id to use for storing a per-user session key that identifies which form session the current user is working with. Default:Lexal\\SteppedForm\\Form\\Storage\\NullSessionKeyStorage(no per-user session key). Provide an implementation (for example, a session-backed storage) when you need to isolate multiple concurrent form sessions per user or to resume a specific form session. Must implementLexal\SteppedForm\Storage\SessionKeyStorageInterface;
Usage
-
Configure your form settings.
use Lexal\HttpSteppedForm\Settings\FormSettingsInterface; use Lexal\SteppedForm\Step\StepKey; final class FormSettings implements FormSettingsInterface { public function getStepUrl(StepKey $key): string { // return step URL } public function getUrlBeforeStart(): string { // returns a URL to redirect to when there is no previously renderable step } public function getUrlAfterFinish(): string { // return a URL to redirect to when the form was finishing } }
-
Declare form definitions in YAML or XML (deprecated since Symfony 7.4).
-
Inject and use the form in your controller. Form is available in the Symfony container as
stepped_form.form.<form_name>.CustomerController.php
use Lexal\HttpSteppedForm\SteppedFormInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; final class CustomerController extends AbstractController { public function __construct(private readonly SteppedFormInterface $form) { } // POST /customers public function start(): Response { return $this->form->start(new Customer(), /* nothing or customer id to split different sessions */); } // GET /customers/step/{step-key} public function render(string $key): Response { return $this->form->render($key); } // POST /customers/step/{step-key} public function handle(Request $request, string $key): Response { return $this->form->handle($key, $request); } // POST /customers/cancel public function cancel(): Response { return $this->form->cancel($this->generateUrl('customers')); } }
License
Symfony Stepped Form is licensed under the MIT License. See LICENSE for the full license text.