1

I'm trying to update the URL on a successful webform submission, with an inline ajax confirmation. The form works and submits fine and I already have a custom Drupal ajax command to history.push setup, but cannot figure out how to hook into the confirmation flow.

I have tried:

  • Adding a custom callback to $form['actions']['submit']['#submit'] and returning an ajax response from that callback
  • Adding a custom handler, but can't see where I could add the functionality necessary

Thanks.

1

I ended up doing this by creating an event subscriber and listening for the webform ajax response as described on this issue page: https://www.drupal.org/project/webform/issues/2911409

The keylines (amended for brevity):

// The event to listen for
KernelEvents::RESPONSE

// Check to see if it is a webform ajax request 
if(
    $event->getResponse() instanceof WebformSubmissionAjaxResponse and
    $event->getResponse()->getWebformSubmission()->isCompleted()
) 

// Add my custom Ajax command
$event->getResponse()->addCommand(new UrlHistoryCommand)
2
  • 1
    Can you please post code samples of what you have implemented? I have come across a similar requirement, not sure how to check whether the form is successfully submitted in Ajax Response Event Subscriber. Please provide more info, Thanks.
    – Mathew
    May 11 '18 at 16:52
  • 1
    Answer updated :)
    – user69676
    May 14 '18 at 6:31

Your Answer

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