Closed (fixed)
Project:
Webform
Version:
7.x-4.1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
29 Oct 2014 at 23:27 UTC
Updated:
14 Nov 2014 at 00:04 UTC
Jump to comment: Most recent
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 commentedComment #2
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 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 :)