1

I'm using drupal 8 and webform module (multistep). In the webform submission settings, i enabled submit several drafts which adds the 'save' button for saving the progress. When the user logs out and logs in later on, a messsage to 'load pending draft' appears. In my settings, each user is allowed one submission. Is there a way to automatically load pending drafts without clicking on the link in the said message?

Appreciate any help given, thanks

0

There is. When a user's saves draft a token gets generated. You need to get their token value.

$webform_submission = \Drupal\webform\Entity\WebformSubmission\WebformSubmission::load($sid);
$token = $webform_submission->getToken();

Then, you need to generate a URL like this

$draft_url = '/form/webform-name?token=' . $token

and on login redirect them to that url.

| improve this answer | |
  • Hi, thank you for your reply, would you plz let me know where to place the code above? – ram_griever Mar 6 at 13:20
  • @ram_griever well depends on where you want to do the redirect. Either hook_user_login or hook_user_view. PS: the code above is not all complete, you still need to query the db to get the $sid (submission id) that belongs to the currently logged in user. – No Sssweat Mar 6 at 13:26
  • Alright thanks, will try it and get back to you – ram_griever Mar 10 at 8:48
  • 1
    hi, sorry for the late reply, i've figured it out without coding, it was in the webform submission settings, click 'limit users to one weborm entity' and then select 'authenticated users' in the section 'Allow users to save and finish the webform later' and that was it, let me know if it works out – ram_griever Mar 18 at 20:26
  • 1
    in the basic settings, i've defined the 403 (login page) and 404 (the initial webform), plus the default front page is the webform intended – ram_griever Mar 18 at 21:18

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.