0

I am trying to programatically get the webform submission sid on submitting a webform but failed to get it !

On my customwebformhandler.php file i have the below:

public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
// Get an array of the values from the submission.
    $values = $webform_submission->getData();

    // Get the Webform submission "Sid".
    $sid = $webform_submission->id();

// Show a success message.
    \Drupal::messenger()->addMessage(t("$sid"));    

}

but i am not getting any sid value.

any help please ?

0

So it turns out i will have to save the webform before i can get its sid since i am using the public function submitForm which is fire in submitting the webform but before saving it.

Final code will be:

public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
// Get an array of the values from the submission.
    $values = $webform_submission->getData();
    // ...
    $webform_submission->save();

    // Get the Webform submission "Sid" after saving the webform submission.
    $sid = $webform_submission->id();

// Show a success message.
    \Drupal::messenger()->addMessage(t("$sid"));    

}

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.