Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm using a webform in a block and want to add default value in a webform field with data from the current node.
so adding a default value with something like [node:field_price] or [current-page:field_price] are all empty
How can I add node field data to a webform field ?
Comments
Comment #1
DanChadwick CreditAttribution: DanChadwick commentedComment #2
DanChadwick CreditAttribution: DanChadwick commentedUse the token browser to ensure that you have the right token. [current-page:field_price] is not a valid token. The [node:field_price] would be the WEBFORM's node, not the node that the block is displayed on (assuming it is displayed on a node page.
If this is not what you want, you will need to use some custom programming and implement hook_form_webform_client_form_alter() to adjust the default values to what you want.
Comment #3
jorisx CreditAttribution: jorisx commentedAh the current use of tokens don't work on the page and page fields a block is added too?
and so [node:field_price] is empty because the webform block is referring to the webform node and not the page it is added as a block...
I'm not a php-programmer but I would need something like this: https://www.drupal.org/node/1558246 ?
or with a custom token, but that involves also some deeper php scripting https://www.drupal.org/node/1849804
EDIT:
ok, got this to work with creating a custom token!
following this guideline: https://www.drupal.org/node/1849804 i can now add custom field tokens from the page/node as a default value in an embedded webform-block field.
- install module token_custom http://drupal.org/project/token_custom
- add a new token via /admin/structure/token-custom
- create a new custom token with name "nodeprice" of TYPE: custom
- use php filter with following code (you need to enable the module PHP filter)
And now i can use the token [nodeprice] in a webform blok as a default value :)