3

I have created a couple of webform submit handlers before, but my new one fires on every page submit rather than when the last page is submitted.

How do I get the webform handler to only fire after the full form is submitted?

Below is what I have at the moment, which fires on each page:

namespace Drupal\the_api\Plugin\WebformHandler;

use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;

/**
 * Webform submission remote post handler.
 *
 * @WebformHandler(
 *   id = "membership_api_post",
 *   label = @Translation("New Membership to API"),
 *   category = @Translation("External"),
 *   description = @Translation("Posts a new membership through to the API."),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED,
 * )
 */
class NewMembershipWebformHandler extends WebformHandlerBase {

  /**
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   * @param \Drupal\webform\WebformSubmissionInterface $webform_submission
   */
  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    parent::submitForm($form, $form_state, $webform_submission);

    kint($form_state);

  }
}
4

You can use $webform_submission->getState() to determine if the submission is completed. The EmailWebformHandler includes decent examples on how to the submission state. I recommend trying to use WebformHandler::postSave() instead of WebformHandler::formSubmit().

  • Thanks I was trying to tweak the @WebformHandler settings, switching to the postSave() method did the trick. – Duncanmoo Dec 1 '17 at 8:35

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.