PHP code example of lexal / symfony-stepped-form

1. Go to this page and download the library: Download lexal/symfony-stepped-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lexal / symfony-stepped-form example snippets



return [
    Lexal\SymfonySteppedForm\SteppedFormBundle::class => ['all' => true],
];

    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
        }
    }
   

   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'));
       }
   }