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.
I'm trying to use user profile fields to auto populate values in my web form, but it does not seem to work.
Am I doing something wrong?
Below are the tokens I'm trying to place in the text area to pre-populate it with the address.
%profile[field_user_address]
%profile[field_user_city], %profile[field_user_province] %profile[field_user_zip]
Comments
Comment #1
Liam MorlandTokens generated by Webform Tokens are in the form:
[webform:val-field_key]
Starting tokens with % only works for Webform's internal token system.
I don't know if it is possible to pre-populate the fields as you are trying to do. That would be an issue for the Webform queue. You can move this issue there is you need more help with that.
Comment #2
sashkernel CreditAttribution: sashkernel commentedBut what's the %profile.... token for. Isn't it supposed to pull values from user profile, or am I wrong?
Comment #3
Liam MorlandYes, I think so, but that is a token created by Webform, not by the Webform Tokens module (I know it is confusing), so I am moving this to that queue.
Comment #4
cmejo CreditAttribution: cmejo commentedI'm having the same problem with the 3.18 version. I have this working on another d7 install with no problem (pulling data from the user registration info) using %profile. On a new install, I can't get it to pull the data. Liam, can you offer some clarification of #1? I tried it with the key being 'first_name' and webform printed [webform:val-field_first_name]
@sashkernel- did you solve this?
Thank you
Comment #5
Liam MorlandTry [webform:val-first_name]
Comment #6
cmejo CreditAttribution: cmejo commentedThank you for your response Liam! I tried '[webform:val-first_name]' without the quotes, exactly as you wrote in the default value box and when I view the webform, it shows '[webform:val-first_name]' again, nothing rendered from my user registration field_first_name... Any ideas why this is happening? What else can I try?
Alternatively, do I need to install another module, perhaps webform_tokens to make this work? Does it work better in 4.x?
Comment #7
Liam MorlandYou need Webform Tokens module for tokens of that style to work. The development version has just recently been updated to work with Webform 4.
Comment #8
cmejo CreditAttribution: cmejo commented@Liam thanks for your quick reply! So I want to install this module? http://drupal.org/project/webform_tokens
I ask because it says that it's not meant for working inside webform...
Will it work with webform 3.18?
Comment #9
Liam MorlandThe development version should work for Webform 3 and 4. The latest release, only for 3.
The tokens created by Webform Tokens can be used by things like Fill PDF. I don't know if they work everywhere where the tokens generated by Webform work. Give it a try.
Comment #10
cmejo CreditAttribution: cmejo commentedIt still didn't work. I'm putting '[webform:val-first_name]' in my webform's first name field, so the user doesn't have to reenter their first name (as all users must be logged into the site to access this webform), all they have to do is click submit. Is this what webform_tokens is for? Is there additional configuration somewhere?
Thanks again!
Comment #11
Liam MorlandWebform Tokens provides tokens for the data as user has submitted to a Webform when they complete that form. You are after tokens for data already in Drupal.
If they have to be logged-in, why have a first name field at all? You're just asking them for information you already know.
Comment #12
cmejo CreditAttribution: cmejo commented@Liam, because I am using webform to get the data into salesforce with the web2lead salesforce module (http://drupal.org/project/sfweb2lead_webform). The only way to get the data into salesforce is with webform as far as I know (we don't have access to the full APIs so we can't take advantage of the salesforce modules with more options). Is there a way for webform to receive the first name and last name from the logged in user's account profile page?
Comment #13
Liam MorlandI think you can do that with the tokens built into Webform, but I haven't done something like that so I don't know exactly what you have to do. You might have to make a simple custom module which sets the values of Webform components on submit. You can use the hidden component type so that your users don't see the fields that they don't have to fill in.
Comment #14
tknospdr CreditAttribution: tknospdr commentedAdding my comment that %profile[key] does not work for me either.
Per Webform's setup page:
Is it possible that there is another module called profile that this info is taken from and it's not meant to work with the internal user nodes?
Thanks,
David
Comment #15
tknospdr CreditAttribution: tknospdr commentedComment #16
loopy1492 CreditAttribution: loopy1492 commentedProfile token also not working for me.
The user in our system also has an Agency email tied to their account registration. This email, as well as the user's email, must be sent a message when the form is completed.
Works:
%useremail
Does not work (Agency Contact Email Address):
Actual machine name given in /admin/config/people/accounts/fields:
%profile[field_agency_contact_email_addre]
Without the "field_":
%profile[agency_contact_email_addre]
Non-truncated of both:
%profile[field_agency_contact_email_address]
%profile[agency_contact_email_address]
Is the key not the machine name?
Is there a place we can get the list of keys out of our system?
Comment #17
loopy1492 CreditAttribution: loopy1492 commentedI also just tried it by removing the underscores and by just putting a number in case it's just trying to reference an array (%profile[1]), but those didn't work either.
I noticed there's no "admin/user/profile" anymore. I was using this to figure out how to use the module:
http://drupal.org/node/296453
I wonder if changes in 7 broke this somehow. We are talking about the fields added on this page, right?
/admin/config/people/accounts/fields
Comment #18
loopy1492 CreditAttribution: loopy1492 commentedI used this.
http://drupal.org/node/1308722#comment-5979152
Not elegant, but my only option at the moment.
Comment #19
quicksketchHi @loopy1492. The reason those tokens are working is because Field module fields are deeply nested. The %profile token support was added to support the core "Profile" module, which still exists in D7, but only if you were using it in D6 and upgraded your site. Profile module would put values directly in the $user object, such as
$user->profile_first_name
. However considering Profile module is no longer being updated or used on most sites, I wouldn't recommend using Profile module today on a D7 site.In order to access a Field module value, you would need a token like
%profile[field_agency_contact_email_address][und][0][value]
, but Webform doesn't support deeply nested tokens at all (see #824606: Webform tokens (%session, %post) do not support arrays).The end solution for all of these problems is to use Webform 4.x, which does away with Webform's custom tokens entirely and just uses the built-in token system of Drupal 7. Then you can use any tokens you like as long as token module supports them.
Comment #20
quicksketchComment #21
tknospdr CreditAttribution: tknospdr commentedI had this working somehow on a D7 site with Webform v3. However, I just updated Drupal and all my out of date modules and it's now not working again.
My tokens were in the form of "[current-user:field_full_name]" but now instead of rendering them, it just prints out that text.
Any help greatly appreciated.
My web host is still on PHP 5.2 so I can't upgrade to Webform 4 BTW.
Comment #22
tknospdr CreditAttribution: tknospdr commentedComment #23
quicksketchWebform 4.x is the only version that supports full tokens like this. In Webform 3.x, only tokens with the format of %user[profile_value] work. Unfortunately, these tokens don't work with Field module fields. Perhaps previously you were running https://drupal.org/project/webform_patched?
Comment #24
tknospdr CreditAttribution: tknospdr commentedI just looked at my backup.
It appears I was running 7.x-4.0-alpha6
So I guess that the PHP restriction came into play after I built this site.
That really blows. I guess I can always downgrade and just ignore the constant nagging to update.
Comment #25
quicksketchYeah sorry about the surprise dependency. When we introduced the Excel-native exporter, it depended upon some PHP 5.3 functionality (that was alpha8 I believe). Your only good option is to stick on the previous version until you can upgrade PHP on your host (or move to a host that has PHP 5.3).
Comment #26
Liam MorlandPHP 5.2 has not been supported in over 3 years. I would question the quality and security of any host that allows such out-of-date software to be in use on the open web. Support for PHP 5.3 ends this July.
Comment #27
panditvarun20 CreditAttribution: panditvarun20 commentedI also having same problem. Can anyone help me from this. Should I write any php code for this ?
Comment #28
quicksketch@panditvarunHSK: This question has already been answered. %profile tokens don't work in Webform 4.x, and you can't access field tokens in Webform 3.x. The solution is to 1) upgrade to Webform 4.x and then 2) use the new tokens formatted as [current-user:field_field_name].
I'm marking this issue fixed since everything has already been answered here.
Comment #29
magpie5212 CreditAttribution: magpie5212 commentedShouldn't the help text under Token Values be changed to reflect this?