I hope I'm not missing something obvious but I can't seem to get the %title token to render as a field's default value. It just prints the letters "%title".
More specifically my form is being used as a block. Basically I would like for the form to be able to grab the title of the node it is embedded in and include that as part of the record/email.
I also considered a Markup field. While I was able to get the title to print on screen, it didn't get recorded in the record or sent in the email.
Perhaps some sort of extra processing module would do the trick, but isn't this what the %title token is for?
Thank for your help, and thanks for the fantastic module.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | webformnodetokens-1224130-7.patch | 658 bytes | alexdmccabe |
Comments
Comment #1
p.selfin commentedIn webforms for Drupal 6 some problem for %title in default value.
---
Sory for my english
Comment #2
jibranHi,
%title and %nid are not working when viewing webform as node or block. I am using %nid as default value. I am getting uri in %get[q] and it is showing right node id. I tried to look into the code and found that when it reaches line 2661 in webform.module $node is NULL.
Comment #3
quicksketchNot critical; duplicate of #1207374: Node tokens (provided by Webform) don't work as default values or description.
Comment #4
jaymallison commentedThis isn't a duplicate. It's a 7.x issue vs the other which is a 6.x issue. And on 7.x-3.12 node tokens don't render in emails. They just leave white space behind.
Comment #5
jaymallison commentedAfter further investigation, it isn't node tokens in general but the %title specifically. If I output the contents of the $node object when it's accessed in _webform_filter_values, the title ordinal is empty, the rest of the node's info is there though. This is weird.
Comment #6
jaymallison commentedI traced this all the way back to function webform_client_form_submit in webform.module.
For some reason the $form['#node'] object doesn't have the title ordinal set. I don't know enough about the form api in D7 to trace it back any farther than that.
For now I HACKED this bad solution, as I had to have a solution for this today (site going live deadline in a couple days)
I took the nid from the $form['#node'] and supplied it to node_load to get a fresh copy of the node. This grabbed the title successfully. I then merged the title back into webform's $form['#node'] copy of the object. I figured that I should at least preserve whatever specific info is in that copy of the object instead of just supplying the new node object to webform. Again, this is my own very limited understanding of the situation talking.
My code is this (terrible, yes I know).
The last two lines are what I added to grab the title and insert it into the object. Hopefully someone with more knowledge knows why the title is absent in the first place and can fix it the correct way.
This fixed the %title token for me in my submission emails.
Comment #7
alexdmccabeI was having the same trouble, came across this issue, and decided to try cutting up webform a little bit on my own. Turns out this seems to solve it. This is the first time I've tried to put a patch out there, so I'm pretty sure this is a terrible, awful hack, and I've done (at least) fifty things wrong. If so, please let me know what they are, so I can improve!
Comment #8
dddbbb commentedHaving the same problem with the %title and %nid tokens. Can confirm that the patch in #7 works.
Comment #9
quicksketchThanks guys for your research into this issue (especially jaymallison, that's extremely helpful information). I'll see if I can reproduce and figure out why $form['#node'] is missing a title, otherwise we may need to implement a solution similar to what #6 recommends.
Comment #10
koppie commentedI had the same problem. I have a webform in a block and I need it to pull an email address from a View and mail to that address. I'm using Webform PHP, in spite of the developer's grumbling, because it really is the most expeditious way to do what I need to do. In terms of it being a bad idea to expose raw PHP on a Drupal site, that horse left the barn a long time ago (at least on my site). The real key is only giving access to trustworthy users.
Anyway I'm using Webform PHP to load the View, get the email address, and send the email. Webform still has trouble getting the NID when it's embedded as a block, so I created a hidden Webform field and used javascript to populate it with the nid.
Not really a fix, but a workaround. Hope that helps.
Comment #11
benjas commentedThanks amccabe. Tried the patch but did not work instead added the code manually and this worked for me.
Comment #12
jamoralesr commentedThanks amccabe
Comment #13
mparkes commentedAny updates on this issue, I'm having similar issues with pulling the node title into a webform block hidden field. I'm cool with adding the code. It's just webforms module has security updates all the time and when I or someone on my team updates it, changes will be lost. Unless of course a hack this bad makes it into the next release...???
Comment #14
quicksketchWebform is maintained in-sync between D6 and D7, there's no point in having two issues for every bug. This is a duplicate, please see the other issue.
Comment #15
knalstaaf commented(offtopic)
I understand this may be the overall policy, but I find it sometimes confusing finding a patch in a thread that's been used for both D6 and D7. Sometimes it's not really clear what version the patch in a combined D6/D7 thread is for. This thread for instance.
Comment #16
pvasili commentedit can be replaced by:
Comment #17
BeaPower commented@#16 - which file do you edit?
Comment #18
Funkwarrior commentedthe patch in #7
Comment #19
vildoc commented#7 after 6.x-3.17 update, stopped working.
Comment #20
ambientdrup commentedThe patch in #7 works but it gives you the title and node ID of the Webform node. I'm using a module called Webform Block to embed the Webform into another node. How can I get the nid and title of the node that I'm embedding the webform into?
Here's more about the Webform Block module: http://drupal.org/project/webformblock
-Trevor
Comment #21
kuydigital commentedPatch at #7 worked perfectly. Thanks amccabe
Comment #22
mrpeanut commented@ambientdrup Did you ever find a solution for your problem? I'm looking to do the same.
Comment #23
knalstaaf commentedI think this will make your day: #1782042: Title of node in webform block
Comment #24
pvasili commented#7 does not work for new version of the module...
If I use the webform in the block I see a address for webform :(
Comment #25
quicksketchThe patch provided in #7 was not what the %title token was intended to provide: the %title token is for the title of the Webform, not the current page. The 3.x version of the module does not provide a token for the current page at all. In the 4.x version, you can use [current-page:title] and [current-page:url]. To get additional node properties from the current page's node, you'd need the token system to provide a "current page object" token, which has a patch at "needs review" over here: #919760: Add a [current-page:object:?] dynamic token
So in summary, you can't get the current page's title in the 3.x branch (you *can* get the current page's URL with either %get[q] or %server[REQUEST_URI]). @knalstaaf's suggestion of using the "webform_patched" module is the only way to add D7-style tokens to the 3.x branch.
Comment #26
pvasili commentedquicksketch, thanks for your comments
I use webform as block, and want see %nid and %title each page (not webform)
1 - I use 6.x version, D6 and I can not update it.
2 - Webform 6.x has no 4.x branch.
3 - All tokens in webform_patched module also show only webform page :(
The #7 after 6.x-3.19 update, stopped working :(.
Comment #27
quicksketchI'm assuming you've put the Webform in a block, right? The 4.x branch and webform_patched (which essentially is just the token system backported) can use [current-page:title] and [current-page:url]. Those are for the current page you're on, not the Webform itself. If you were more familiar with PHP, I'd recommend using hook_form_alter() to set a default value. But if that's not an option, webform_patched is probably your best bet.
Note that you *can* still record the current page URL by using %get[q] as the token. That will record the internal Drupal path of the page. You can set the default value of a hidden field to
http://example.com/%get[q]if you would like to make it a full URL.Comment #28
pvasili commentedquicksketch, thanks
Yes
I tried to use the module webform_patched.
1) I added 2 tokens ('curent-node-nid' and 'curent-node-title') and checked them out on the title.
All works! I see my page nid.
I added this token in the hidden field webform and see nid webform :(
2) I try us #7 in the module webform_patched and see nid webform :(
mysticism...
Comment #29
quicksketchThere's an actual bug with hidden fields and tokens, as reported here: #1580700: Hidden "secure value" component losing its token (%get, %post) value on webform submission. If you change the "Hidden type" from "Secure value" to "Hidden element" it should maintain the token value in the submission.
Comment #30
dropfen commentedIf you need just the value of the current loaded node (www.example.com/node/nid)
you could use menu_get_object() for example and put this value in a field of your form, just need to write
a simple hook_form_alter function.
Sorry, if I have misuderstood your issue..
Comment #31
quicksketchAgain: #919760: Add a [current-page:object:?] dynamic token
This is not a bug in Webform. %title (3.x) and [title] (4.x) will give you the title of the Webform. It is intentional and the way tokens work everywhere in Webform. You guys are all wanting a token for the *current page*, which is what that issue is for. Note that there isn't a way to get this feature in the 3.x branch of the project. No new features are being added to 3.x at this point.
Comment #32
jasom commentedYes, you can have current page title in your email using Webform 4.x module, but at first apply this patch for Token module.
Token which does the main trick is [current-page:query:?]. It can extract each field of the current node and insert it into the message, subject, recipient... For example token for the date the current node was posted will looks like:
Also, there is direct token for this: [current-page:title]
You can find more details in my post.
Comment #33
SathyaSheela commentedUse of undefined constant , will sometime make tokens to disappear from your token browser.
Check your error log - Fixing 'Use of undefined constant' issue will fix tokens issues as well.