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.
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
Comment #1
quicksketchThat'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.
Comment #2
XC1 CreditAttribution: XC1 commentedI'm using a webform in a block and the token [current-page:url:brief] correctly shows the page url.
Comment #3
zambrey CreditAttribution: zambrey commentedI'm using alpha4 and it still redirects me to webform page.
Comment #4
cainrus CreditAttribution: cainrus commented+1 same thing for webform alpha4
Comment #5
bessone CreditAttribution: bessone commented+1 same thing to me on alpha4, page title and redirect to the webform page, not the block page.
Comment #6
bessone CreditAttribution: bessone commentedAfter 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?
Comment #7
cainrus CreditAttribution: cainrus commentedGuys, you can solve this with custom token module. Create new token with php code:
And then use it instead of [current-page:url]
Comment #8
bessone CreditAttribution: bessone commentedIs 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.
Comment #9
whizzkid CreditAttribution: whizzkid commentedI 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.
Comment #10
whizzkid CreditAttribution: whizzkid commentedIn 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.
Comment #11
whizzkid CreditAttribution: whizzkid commentedIt all seemed to start behaving as expected for me when I ticked "Show all webform pages in block" in the block settings.
Comment #12
machete1 CreditAttribution: machete1 commentedPost #11 is the solution!
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks a lot whizzkid, it solved my problem !!!!!
Comment #14
amruta87 CreditAttribution: amruta87 commented#11 solved my problem too..
Comment #15
quicksketchThe latest release of Webform 4.x now makes this setting the default.
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.
Comment #16
edwardchiapet#11 solved my problem -- thanks!
Comment #17
bryanhidalgo CreditAttribution: bryanhidalgo commented#11 solved my problem too.. thanks!
Comment #18
DD 85 CreditAttribution: DD 85 commentedPrompt, what token used to convey the meaning of the field?
Comment #19
jorisx CreditAttribution: jorisx commentedTokens from custom fields are still not available in a webform block with webform 7.x-4.1
[node:field_mycustumfield] does not work ...
Comment #20
hmartens CreditAttribution: hmartens commentedI'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?
Comment #21
DanChadwick CreditAttribution: DanChadwick commentedYes. 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.
Comment #22
hmartens CreditAttribution: hmartens commentedThank 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.
Comment #23
DanChadwick CreditAttribution: DanChadwick commentedSome 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.
Comment #24
DanChadwick CreditAttribution: DanChadwick commentedAlso, please open a new issue next time. Your question isn't directly related to this issue.
Comment #25
RAWDESK CreditAttribution: RAWDESK commentedTried #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
Comment #26
louisalexandrecazal CreditAttribution: louisalexandrecazal commentedI 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...