0

I am building a webform that has multiple pages. The idea is that the user leaves the wizard after each page that he submits. When he later returns, he automatically starts the form on the unanswered page.

The reason for this behaviour is that doing so, we can keep the records of all the 'sub-surveys' together as one single submission.

I successfully have set up custom handlers based on the example module. I can see that the handler is working.

To accomplish the desired scenario, I thought that it is probably best to log the user out in the {submitForm} function of the handler and set the redirect ($form_state->setRedirect).

The redirect doesn't happen, but the logout does. What I end up with now, is that the user sees his next page, but can't submit it because he is actually logged out. It's fine that he can no longer submit. But it's not ideal that he sees the next page in the form. That is why i try to redirect.

I read in another question on stackexchange that the redirect should be set in the confirmForm, but that doesn' work either. Maybe because confirmForm only happens at the end of the wizard or something.

Any suggestions on how to redirect after (each, or some based on a condition) pages from the wizard?

Thanks.

1 Answer 1

0

The logout is probably losing the user's session with the $form_state

A very simple solution is to redirect the form to /user/logout?destination=REDIRCT_PATH.

2
  • thx for the suggestion. It seems to be that the redirect (configured with $form_state->setRedirect) only triggers when the form reaches the end state. So regardless of where I configure it (submitForm or confirmForm), it only happens and redirects when the 'complete' step of the form is reached. I try to trigger the actual redirect to happen after the draft of the current page is saved.
    – pieterdt
    Commented Jan 18, 2019 at 8:42
  • I don't like this solution, because it severly interrupts the flow of drupal, but this works: create a new response and force the browser elsewhere: $response = new redirectResponse(\Drupal::url('<front>')); $response->send();
    – pieterdt
    Commented Jan 18, 2019 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.