The new token support is great, I have one question though related to [current-page:url] token.
When submitting a form in block I would expect that [current-page:url] returns url of the page I'm currently on. Instead it points to webform url.

It happens in emails and redirection. Is it a bug or normal behavior?

Comments

quicksketch’s picture

Title: Webform as block and [current-page] token » Webform as block [current-page] token uses Webform's path instead of current page
Category: support » bug

That's odd, I would expect it would do the page you're on also. I haven't confirmed this problem, but it sounds like a bug to me.

XC1’s picture

I'm using a webform in a block and the token [current-page:url:brief] correctly shows the page url.

zambrey’s picture

I'm using alpha4 and it still redirects me to webform page.

cainrus’s picture

+1 same thing for webform alpha4

bessone’s picture

+1 same thing to me on alpha4, page title and redirect to the webform page, not the block page.

bessone’s picture

After some tests if found that using a hidden field with a token value [current-page:title], it works with hidden type "Hidden element" but don't works with "Secure value".

With hidden element the value is already populated in the form, maybe with secure is populated only after submit, so the current page is no more the page with block but the webform page, right?

cainrus’s picture

Guys, you can solve this with custom token module. Create new token with php code:

<?php
  return 'http'.(empty($_SERVER['HTTPS'])?'':'s')."://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
?>

And then use it instead of [current-page:url]

bessone’s picture

Is not a clean solution, can work with the page url, but for the page title?

The problem is how webform use the "Secure value", if not enabled everything work fine.

whizzkid’s picture

I can confirm this problem with version 7.x-4.0-alpha6+0-dev

Everything works as expected (token values come from the page the form was submitted from) if the hidden type is set to "Hidden element" but not if the hidden type is set to "Secure value"

I have the form in a block and I'm using the custom tokens module to add a token for the page author's email address, so I really must use "Secure value" to keep this value out of the HTML sent to the browser.

Maybe the issue title should be updated to reflect the problem is specific to Hidden components with a secure value type.

whizzkid’s picture

In my testing I wasn't actually using the custom tokens module - I was using the current-page:title token which exhibits the problem. I currently have 2 hidden components both set to current-page:title one secure and one hidden element. They end up with different values when I look at the results.

The token generated by the custom token module works as it should, when it is secure or a hidden element.

whizzkid’s picture

It all seemed to start behaving as expected for me when I ticked "Show all webform pages in block" in the block settings.

machete1’s picture

Post #11 is the solution!

Anonymous’s picture

Thanks a lot whizzkid, it solved my problem !!!!!

amruta87’s picture

#11 solved my problem too..

quicksketch’s picture

Status: Active » Closed (duplicate)

It all seemed to start behaving as expected for me when I ticked "Show all webform pages in block" in the block settings.

The latest release of Webform 4.x now makes this setting the default.

After some tests if found that using a hidden field with a token value [current-page:title], it works with hidden type "Hidden element" but don't works with "Secure value".

This is actually the root cause of this issue: #1580700: Hidden "secure value" component losing its token (%get, %post) value on webform submission. This problem only occurs with "Secure" hidden values. The explanation for it is that issue. Let's consolidate with that issue.

edwardchiapet’s picture

Issue summary: View changes

#11 solved my problem -- thanks!

bryanhidalgo’s picture

#11 solved my problem too.. thanks!

DD 85’s picture

Prompt, what token used to convey the meaning of the field?

jorisx’s picture

Tokens from custom fields are still not available in a webform block with webform 7.x-4.1
[node:field_mycustumfield] does not work ...

hmartens’s picture

I'm also struggling to use tokens from custom fields.

I have an event and the event has a "Event Number" and the fields is "field_event_number". Underneath the event I have a webform block where people can register for the event. In the webform I have a field for people to type in the "Event Number" and I made it the "Default Value": [node:field_event_number]

But it doesn't work because on it just shows [node:field_event_number] in the webform field where it's supposed to show the Event Number.

Am I doing something wrong?

DanChadwick’s picture

Am I doing something wrong?

Yes. The node in the token is the webform's node. It has no idea that you happened to put the block on another node's page.

If you can get the data you need into the URL, you can use the current-page tokens to get them. Otherwise, I suggest you write a custom module to implement hook_webform_client_form_alter() to put the data you want from the page's node into the desired webform components.

hmartens’s picture

Thank you Dan for your help. I will try the URL method and try and get it to work.

My thinking is that it should only show me the tokens that are available to me in this webform or content type, not every token on my site?

Thank you.

DanChadwick’s picture

Some tokens are provided by the token module -- the current user, the current page (URL, arguments, etc), some random tokens, etc. Others are provided by the context where they are to be used -- the node, webform submission, and webform e-mail.

DanChadwick’s picture

Also, please open a new issue next time. Your question isn't directly related to this issue.

RAWDESK’s picture

Tried #7 because i believe it's the most configurable/customizable option, but on Webform 7.x-3.x custom tokens are not exposed to webform components.
On Webform 7.x-4.x they are supported but the upgrade path is too drastic for just enabling a custom token.
In the end this solution brought me to my goal of setting (default) values in my webform :
https://www.drupal.org/node/1470748#comment-5781628

Thanks @quicksketch

louisalexandrecazal’s picture

I don't know if this is more relevant here or in the panels module thread but the issue seems to be similar to what I am experiencing with [current-page:title]. In a webform block positionned in a pannel, I can't get the current page title to be displayed as a default value.
End goal is to use that default value in a hidden field and use that fied in the webform email subject.
[current-page:url] and the likes work. But the page title... no clue...