diff --git a/src/EventListener/PrepareFomDataListener.php b/src/EventListener/PrepareFomDataListener.php index aa09652..cd54555 100644 --- a/src/EventListener/PrepareFomDataListener.php +++ b/src/EventListener/PrepareFomDataListener.php @@ -38,7 +38,14 @@ public function __invoke(array &$submitted, array &$labels, array $fields, Form $labelsBag = new ParameterBag($labels); $pageSwitchValue = $submittedBag->get('mp_form_pageswitch', ''); - $submittedBag->remove('mp_form_pageswitch'); + + // Remove the page switch value field from the submitted data if that's the last step, so it's not passed on + // in e-mail notifications and the like. However, in intermediate steps we need it because otherwise it's not + // possible to have an empty step (e.g. only explanation fields) as the step data would be empty and + // getFirstInvalidStep() would return the one before the empty step. + if ($manager->isLastStep()) { + $submittedBag->remove('mp_form_pageswitch'); + } // Store data in session $stepData = $manager->getDataOfCurrentStep();