Trigger redirect after Webform Remote Post Handler posted successfully

Drupal Answers Asked by Jessica IX on December 10, 2021

I’ve made a webform with a handler. This handler does a Remote Post towards an API. This API is actually a custom module within the Drupal install which (after some logic) passes all of the preprocessed data towards another API. When that is passed successfully I get a redirect URL back from them, but whatever I use (TrustedRedirectResponse or just normal RedirectResponse) it won’t redirect. It just reloads the form.

How to solve this?

One Answer

I've added the following to the handler:

* {@inheritdoc}
public function confirmForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  if ($this->isDisabled()) {

  $uri = new Url('entity.node.webform.user.submission', [
    'node' => $webform_submission->getSourceEntity()->id(),
    'webform_submission' => $webform_submission->id(),
  $form_state->setResponse(new RedirectResponse($uri->toString()));

This seems to work.

Answered by h3rj4n on December 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP