0

I have a webform with the confirmation set to redirect to URL (redirects to a custom path or URL) In my webform handler, I have the following:

public function confirmForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  $url = "https://SOMEURL.com";
  $url = Url::fromUri($url);
  $form_state->setRedirectUrl($url);
}

I verify with xDebug that $url contains a valid Url object with the correct value in its uri property, but the form then redirects to the path in the placeholder and not the new one.

6
  • I would use Xdebug to step through the form submission process and make sure that my setting the redirect URL happens last, i.e. make sure I'm not setting the redirect path before the form owner, e.g. webform.
    – sonfd
    Jun 16 at 14:47
  • 2
    Is this code part of a plugin? Without context we can't really tell you anything.
    – Jaypan
    Jun 16 at 14:54
  • Interesting point. With all the examples I’ve seen of how to redirect the webform upon submission using the confirm method, what would I do if webform is setting that after I do? Maybe my choosing the redirect confirm action in the config options was the wrong way to go… if it is applying after me, maybe that is why. I’ll also check if there is a no-action like option.
    – JAyenGreen
    Jun 16 at 14:56
  • It's confirmForm for webform, which makes it a webform handler.
    – JAyenGreen
    Jun 17 at 2:01
  • ... which is a plugin, see drupal.stackexchange.com/questions/245285/…
    – 4uk4
    Jun 17 at 13:59

1 Answer 1

1

The issue was the setting in the UI for the webform confirmation. Instead of selecting redirect to a URL (which is actually what it needs to do), 'none' should be selected, which then adds a description implying that the selection will result in control of confirmation being turned over to a handler.

That is, the other selections will cause whatever the handler does to be overridden, where 'none' will leave alone whatever the handler does to form_state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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