Is there a way to trigger the Emails/Handlers, When webform submission has been updated. I'm using webform_mailchimp as a handler. When I'm submitting a new record, handler is working fine and I can receive the data into my Mailchimp account. I have a function to update the submission via code. But it doesn't trigger, when I update the same record. Following is my code to update the webform submission:

$webform = Webform::load('my_form');
$is_open = WebformSubmissionForm::isOpen($webform);
$sid = 2;

if ($is_open === TRUE) {
    // Load submission
    $webform_submission = WebformSubmission::load($sid);

    // Modify submission values
    $webform_submission->setElementData('preferred_date', $form_state->getValue('preferredDate'));
    $webform_submission->setElementData('preferred_time', $form_state->getValue('preferredTime'));

    // Validate submission.
    $errors = WebformSubmissionForm::validateWebformSubmission($webform_submission);

    // Check there are no validation errors.
    if (!empty($errors)) {
        drupal_set_message(t('Failed! Please contact the administrator.'), 'error');
    else {
        // Submit values and get submission ID.
        $webform_submission = WebformSubmissionForm::submitWebformSubmission($webform_submission);
        drupal_set_message(t("Success! ".$webform_submission->id()), 'status');
  1. Is there a way to trigger the handler through code(programmatically)?
  2. Is there a default configuration in the CMS?

Thanks guys,

3 Answers 3


The below code is untested but should point you in the right direction.

// Get a handler.
$webform_submission = WebformSubmission::load(WEBFORM_ID)
$handlers = $webform_submission->getWebform()->getHandlers();
$handler = $handlers[HANDLER_ID];

// Invoke submit form.
@see \Drupal\webform\Plugin\WebformHandlerInterface::submitForm
$form = []; // Might need to get the $form.
$form_state = new FormState(); // Might need to be build the form state.
$handler->submitForm($form, $form_state, $webform_submission);

@see \Drupal\webform\Entity\Webform::invokeHandlers

@see \Drupal\webform\Entity\WebformSubmission::invokeWebformHandlers

  • How do I get $form and $form_state from $webform or $webform_submission objects? Or do I need to build them in another way? My code is in a class which extends the ControllerBase class...
    – cchen
    Commented Aug 15, 2019 at 3:33
  $webform_submission = \Drupal\webform\Entity\WebformSubmission::load(submission_id);
  /** @var \Drupal\webform\Entity\Webform $webform */
  $webform = $webform_submission->getWebform();
  /** @var \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler $handler */
  $handler = $webform->getHandler(handler_id);
  $message = $handler->getMessage($webform_submission);
  $handler->sendMessage($webform_submission, $message);

In case the above solution doesn't alternative can be this as well.

  • This is just what I was looking for. Thanks!
    – mbomb007
    Commented Mar 2, 2023 at 17:32

If the Mailchimp handler supports it, you can select the option to fire the handler "...when submission is updated" within the handler settings.

enter image description here

  • You can also uncheck all of them, and it will only send when using the "Resend" button or from code.
    – mbomb007
    Commented Mar 2, 2023 at 17:24

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.