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

danchadwick’s picture

Title: webform block, tokes are empty » webform block, tokens are empty
Issue tags: -webform, -token, -node field, -default value
danchadwick’s picture

Status: Active » Fixed

Use 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.

jorisx’s picture

Ah 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)

if(arg(0)!="node")
return "not viewing a node";
$node = node_load(arg(1));
return $node->field_price['und'][0]['value'];

And now i can use the token [nodeprice] in a webform blok as a default value :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.