Score:2

How can I prevent a webform submission from being saved?

bm flag

I'm writing a custom WebformHandler and am wondering how I can prevent a submission from being saved? I've tried using the RESULTS_IGNORED and SUBMISSION_OPTIONAL in the @WebformHandler annotation, but the submissions still get saved. Is there an additional step, say in the submitForm() method?

/**
 * Premium Content Webform Handler.
 *
 * This is a custom handler to tie into the premium content form to handle
 * when the user submits the form and either re-sends them the link to the
 * content, or takes them to the credit card processor to complete the
 * transaction.
 *
 * @WebformHandler(
 *   id = "lazy_handler",
 *   label = @Translation("Lazy Handler"),
 *   category = @Translation("Custom"),
 *   description = @Translation("Only saves on Mondays."),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_IGNORED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL
 * )
 */
class LazyWebformHandler extends WebformHandlerBase {
  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    $is_monday = FALSE;
    if (!$is_monday) {
      // Do I do something here to prevent the submission from being saved?
    }
  }
}
cn flag
The annotation comments for `results` say _When set to TRUE, 'Disable saving of submissions.' can be set._, so (and this is a complete guess), maybe that value should be `RESULTS_PROCESSED` rather than `RESULTS_IGNORED`, and then maybe you need to implement the `WebformHandlerInterface::overrideSettings` method to set `results_disabled` to `TRUE` in the general settings
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.