0

I have a form where images amongst other things are submitted. I need to be able to relate back to the original webform submission where they were submitted in a Drupal View (that is not based on Webform submissions themselves) and so I created a hidden field to store the submission url on the webform itself but it does not get written. I know I can use [webform_submission:url] on the confirmation screen and emails.

I've tried using [webform_submission:token-view-url] but this causes an error on saving that element with respect to rendering the route. The update token, [webform_submission:token-view-url] will save without error and does save but does not give a usable URL.

I assume this is a 'timing thing' where the webform submission does not actually complete and get this information until it is saved etc. Is there a way to do this easily?

1 Answer 1

0

I had to resort to writing a custom Webform Handler to get this to work properly. There are plenty of resources to get you started on doing this, I used the Webform Example Handler code (webform_example_handler) from the Webform module, but if anyone wants the full code, just shout.

I added a webform element of type URL to store the update link. I then created a custom submitForm function to write the update URL to this element:

public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission)
{
    //$this->debug(__FUNCTION__);
    
    if ($webform_submission->isNew()) {// a new submission
        $values = $form_state->getValues();
        // I do other things for my form here...
       // Now write the update URL to my URL element directly into the submission data
       $updateURL = $webform_submission->getTokenUrl('update')->toString();//getTokenUrl is from the WebformSubmission.php
       $webform_submission->setElementData('update_webform_url', $updateURL);
    }
}

I hope this helps others

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.