- Issue created by @daniel_arend
Also, can you explain steps to reproduce that describe the bug behavior, without the value dumping?
- 🇧🇷Brazil daniel_arend
The value dump is part of the bug, because is the only way to detect that is running a double validation on the second step.
- 🇧🇷Brazil daniel_arend
Here follows the code I made. I also attached a video with the bug in action
function mymodule_webform_submission_form_alter(&$form, $form_state, $form_id) { echo '<pre style="background:yellow;">'; var_dump($form_state->getValues()); echo '</pre>'; }
- 🇧🇷Brazil daniel_arend
Here is some explanation about what I tried to fix the issue:
https://excalidraw.com/#json=R75jneYKHbK13FMsuLg7H,uxFDrzKLtZadt8ZxBFm6Cg
Somehow, the step #2 do additional things (rebuild maybe) that trigger the form_alter hook twice. At first trigger, the form_state variable is empty, the 2nd one the form_state values are set as should be.
It seems to be something on the way between stack 1 and stack 4 (link above).
I also tracked the overrideSettings method line by line, but could not find where/why is this hook triggering twice only in the 2nd step.
I hope this info helps to find the root cause. - Status changed to Postponed: needs info
over 1 year ago 2:04am 24 June 2023 - 🇺🇸United States jrockowitz Brooklyn, NY
I am confused because this does not seem to be a regression.
When multistep forms render the form is built (no values), processed (callback), and rebuilt (with values).
- 🇧🇷Brazil daniel_arend
Thanks for the feedback. The workflow you described makes sense. But I'm still stucked into something I can only solve using form_alter hook.
The complete scenario is:
I have a multi-step form and need to do some extra validations after the user clicks on "prev/next" button. So I'm checking form state values inside this form_alter hook.
As it triggers twice (and it happens only on the 2nd step), the first time this info is empty (build), and only after rebuild, the values are set.
This will throw a false validation error (2nd step) on build, and then will pass on the second one, when values are set.It gets more strange, because all other steps (1, 3, 4, etc) it runs only once and works exactly like it should.
As we need to check step by step, a custom handler would not solve the issue.
- 🇺🇸United States jrockowitz Brooklyn, NY
Someone who is experiencing this issue is going to have to debug it.
I am experiencing an issue that is quite the same. In one particular webform, while I am on the 2nd step I click Next to go the 3rd, I am redirected to the 1st step, and I get an error saying that the required fields of the first step are empty. This happens randomly. The behavior is the same as I was on the 2nd step and clicked the refresh button from the browser and then Resend.
@daniel_arend did you manage to solve this?
- 🇮🇳India dhanalakshmi1013
I'm having the same issue, but in a different way. I have a multistep webform with 9 steps and each step data sending to Datalayer GTM. Only 5,6,7 steps are submitting twice in GTM console rest all are sending the event once. While debugging this issue, I have observed that Alter_form where my datalayer JS is attached is calling twice on a single submit.
Can anyone share thoughts on this please!