Score:0

How to persist webform validation result in multistep ajax webform handler?

dk flag

In my AJAX form the user has to do a validation as he needs a code to enter the rest of the form (it has 3 pages or more). I have an handler to validate this and this same handler uses that code to do get a node:

  // ON the handler validate()
  $code_valid= $this->sessionManager->get('code_valid');
  
  if (empty($code_valid))
  {
     $this->handlerProperty = $this->contentService->getContentByCodeAndCurrentNodeId($node_id, $name, $code);
     $this->sessionManager->set('code_valid', $this->handlerProperty);
  }


  // On repository Class
  public function getContentByCodeAndCurrentNodeId(int $node_id, string $name, string $code)
  {
    return $this->entityTypeManager->getStorage('node')
      ->loadByProperties([
        'type' => 'XXXXX',
        'event' => $node_id,
        'name' => $name,
        'code' => $code,
      ]);
  }

  public function confirmForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
     //If submissions is successful, delete private store
     $this->sessionManager->delete('code_valid');
  }

My problem is that there's no way to $this->sessionManager->delete('code_valid') if the user leaves amidst the form. So I was looking for a way to persist the validation result, without resorting to sessionManager/privatestoremanager.

If you want more context the webform is setup to be used on a specific content type (A). It's used to create/update/delete another content type (B). It's a one to many relationship between them so this form will create multiple B dynamically, depending on the form content submitted - it can create up to 5 of B. The first step is a validation/auth to be able to use the "real" form (next steps after first).

Thanks in advance!

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.