1

What I'm trying to do is to invoke some javascript after a webform is successfully submitted by ajax.

To do that I followed this advice and created an EventSubscriber to intercept ajax response and add my custom command there. The problem is that on some reason I can't check if the webform is submitted (data are sent) or not.

  public function onResponse(FilterResponseEvent $event) {
    if($event->getResponse() instanceof WebformSubmissionAjaxResponse &&
       $event->getResponse()->getWebformSubmission()->isCompleted()) {
         $event->getResponse()->addCommand(new MyCustomCommand());
    }
  }

The problem is in isCompleted() method which always returns false on some reason. Actually I checked other methods from WebformSubmissionInterface and in this my event subscriber this WebformSubmission entity always looks empty (getters return nothing) and geState() always returns "STATE_UNSAVED" not depending if a webform is successfully sent of failed on validation.

What I'm missing? Is anything I'm doing wrong here? Or maybe are there any other method to achive same goal?

0

I had this same issue, what worked for me was under webform settings > Confirmation > Confirmation Type. Change the confirmation type to 'Inline (reloads the current page and replaces the webform with the confirmation message)'

This returned true for $event->getResponse()->getWebformSubmission()->isCompleted()

|improve this answer|||||

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.