Score:0

Updated: Webform tokens present user-submitted data for form fields

es flag

I'm attempting to build a webform (Webform 8.x, Drupal 8) that requires the ability for a user to submit the form multiple times.

To simplify the process for users, I'd like to set up some form fields to:

  • be empty by on their first visit to the form
  • for subsequent renders of the form, some form fields should be prepopulated with submissions from the previous submission

Is there a way to achieve this using tokens?

I'm attempting to use tokens to do this (details below) but various approaches aren't working.

All of the examples below address the first_name field, which is in the personal_information fieldset.

I have added the following tokens in the field's default value field with no luck:

  1. This support page about webform tokens (for webform 7.x): https://www.drupal.org/comment/reply/2790291 ...advises that I access the value using:

[submission:values:personal_information:first_name]

...but it doesn't work when I add it to the 'Default value' field. Instead, I receive an error from Drupal saying that:

Default value is using the following invalid tokens: [submission:values:personal_information:first_name].

+++

If I follow the token guidance on the form in Webform 8.x, it seems to advise that I use this structure for my token:

[webform_submission:webform:element:first_name]

...the result is the field's label ('First name') is pre-populated in the field.

If I append the :clear suffix, the result is the same, the field's label is still pre-populated in the field.

This seems is the most successful option so far.

+++

If I add :value to the token:

[webform_submission:webform:element:first_name:value]

...the result is the text of the token is pre-populated in the field.

If I append the :clear suffix:

[webform_submission:webform:element:first_name:value:clear]

...the field is empty on the first and subsequent submissions.

+++

If I use this, which seems to be the guidance in the token section about 'Webform tokens from submitted data':

[webform_submission:values:first_name]

...it renders the text of the token.

If I append the :clear suffix:

[webform_submission:values:first_name:clear]

...the field is empty on the first and subsequent submissions.

If I include the fieldset value:

[webform_submission:values:personal_information:first_name]

...the site returns an error message: "LogicException: The "[webform_submission:values:personal_information:first_name]" is being called recursively..." And a subsequent yaml error after changing it. The only way I can resolve this issue (even after editing the form's yaml via the CMS or the config file) is by deleting the form field and then re-creating it.

+++

If I attempt this:

[webform_submission:values:first_name:raw]

...it renders the text of the token.

If I add the :clear suffix, the field is empty on the first and subsequent submissions.

scaffolding avatar
es flag
This has been addressed here: https://www.drupal.org/forum/support/post-installation/2021-08-04/webform-8-tokens-attempting-to-display-a-fields#comment-14184103
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.