Trying to pre-populate Webform field

Created on 2 January 2024, 6 months ago
Updated 2 April 2024, 3 months ago

Problem/Motivation

I am using ECA to check whether a pdf file has uploaded into a file field. If a file is present, ECA then creates a Webform Node, setting it to the correct form and then naming it.

Then the plan is to pre-populate some fields within the newly created webform before saving it - initially, I am trying to pass through the file URL from the original entity into the webform.

I have created a token containing the referenced file URL and this is displayed correctly in a test message... however, I am struggling to find the correct action(s) to pre-populate the appropriate field in the newly created webform.

Please can you advise the step(s)/action(s) to use to successfully pass the token into the Webform?

The field name (key) in the webform I am trying to pre-populate is called "completed_home_report" and I have tried a variety of actions (such as FORM FIELD: SET DEFAULT VALUE, ENTITY: SET FIELD VALUE, FORM FIELD: SET DEFAULT VALUE, and others) but I'm stumped and can't figure it out myself. I'm guessing the issue is either I'm not using the correct action to pass the token into the webform or/and not using the correct Field Name syntax within the chosen action... However, I may well be off completely!

Steps to reproduce

I have included a screenshot of the model with each step shown to help visualise where I am going wrong.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Closed: outdated

Version

1.1

Component

Tests

Created by

πŸ‡¬πŸ‡§United Kingdom alastairworters

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alastairworters
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    A webform is a config entity, describing how a form should be build, when a user is asked to fill that in their browser. The result of such a submitted webform is then a content entity of the type webform_submission.

    Your description above sounds like you want to create a webform_submission content entity with ECA, right? If so, this issue belongs to the ECA Webform module. And then, once you've created the content entity, you don't want to set field values, as the webform submission field values are webform data, not fields of a content entity. Yes, that's confusing, which is just because it is unfortunate, that webform fields can be mixed and matched with entity fields, which they aren't.

    Side-note: using such a big screenshot of a model is not really helpful for support cases. It's better to create a simple model and export that from the ECA overview page. Such models can then be imported into a fresh Drupal site and are much easier to review then a screenshot.

  • πŸ‡¬πŸ‡§United Kingdom alastairworters

    Apologies for the large screenshot.. I only meant to show visually what my issue was, however I will follow your instructions from now on.

    To answer your question, I am using ECA to create a webform node, referencing from a central webform, rather than creating a webform_submission.

    The model I have created successfully creates a webform node. I am also able to pull through the file URL as a token from the referenced entity and can display the url with in a message to the user. However I am unable to pre-populate a text field within the newly created webform node using the token that contains the URL.

    Reading through the documentation and watching your tutorials I thought that it would be a case of setting the field value of the new webform entity placing the assigned token holding the file URL into a field within the webform node.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I'm not familiar with "webform nodes", hence I'm not sure what that exactly is.

    The "field" you want to populate, is that a node field? Or is it a webform field? If it's the latter, you can use the field API, e.g. "Set field value". For webform fields, there is a completely different data model and there are some ECA actions available in the eca_webform module, that are able to get and set webform data. They are called webform fields in the UI, but they are not fields in terms of node fields.

    To further debug your problem, I'd suggest to forget about the URL in a token. You may try with a fixed string value first. When you managed to pre-set the "field" value with that fixed string, the next step could then be to replace that with a token.

  • Status changed to Postponed: needs info 4 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
  • Status changed to Closed: outdated 3 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
Production build 0.69.0 2024