Skip to content

Commit 39e3c22

Browse files
committed
fixed csrf validation
1 parent e92f059 commit 39e3c22

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Form/Extension/Core/Type/FormFlowType.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Symfony\Component\Form\Extension\Core\Type\FormType;
66
use Symfony\Component\Form\FormBuilderInterface;
7+
use Symfony\Component\Form\FormEvent;
8+
use Symfony\Component\Form\FormEvents;
79
use Symfony\Component\Form\FormInterface;
810
use Symfony\Component\Form\FormView;
911
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
@@ -38,6 +40,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3840

3941
$builder->setDataStorage($options['data_storage'] ?? new NullDataStorage());
4042
$builder->setStepAccessor($options['step_accessor']);
43+
44+
$builder->addEventListener(FormEvents::PRE_SUBMIT, $this->onPreSubmit(...), -100);
4145
}
4246

4347
public function buildView(FormView $view, FormInterface $form, array $options): void
@@ -105,4 +109,14 @@ public function getParent(): string
105109
{
106110
return FormType::class;
107111
}
112+
113+
public function onPreSubmit(FormEvent $event): void
114+
{
115+
/** @var FormFlowInterface $flow */
116+
$flow = $event->getForm();
117+
118+
if ($flow->getClickedActionButton()?->isClearSubmission()) {
119+
$event->setData([]);
120+
}
121+
}
108122
}

src/Form/Flow/FormFlow.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public function submit(mixed $submittedData, bool $clearMissing = true): static
4646

4747
$this->setClickedActionButton($submittedData, $this);
4848

49-
if ($this->clickedActionButton?->isClearSubmission()) {
50-
$submittedData = [];
51-
}
52-
5349
parent::submit($submittedData, $clearMissing);
5450

5551
if (!$this->clickedActionButton || !$this->isSubmitted() || !$this->isValid()) {

0 commit comments

Comments
 (0)