I have a webform with a single handler - an extended remote post handler that sends the submission to an external service. The entire form loads in a modal dialog and has two wizard steps.

This service can return a 200 (with confirmation id and date) or 400 (and any number of errors).

How can I either:

  • Prevent the submission on error from the service, and reload the form to try again (with values retained)
  • Change the confirmation message to reflect that something went wrong, and either reload the form fresh with that appended or just have a link in the modal that goes "back to form"

I have looked at a few other questions like:

I can't get them to work. preprocessConfirmation() is never triggered in my handler, I don't see other examples or where that would be called. How are we supposed to implement that effectively? If there was an error saving the data to the remote service, I either want the user to try again, or just delete the webform submission in Drupal and start over.

1 Answer 1


I believe it is too late to halt the Webform with validation errors once it is past the validation phase ie. in postSave(). If you are expecting validation errors on user input however, then you could move the service call to WebformHandlerBase::validateForm() and then save the service response in the $form_state object if you need it.

   * {@inheritdoc}
  public function validateForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    parent::validateForm($form, $form_state, $webform_submission);

    try {
      $response = $this->doServiceRequest()
    catch (\Exception $e) {
      $form_state->setErrorByName('foo', $e->getMessage());

    // Save service response output.
    $webform_submission->setData($response->getData() + $webform_submission->getData());

Note: This probably goes against the design of the RemotePostWebformHandler, but I think it could work..., or you could directly extend WebformHandlerBase instead.

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.