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

Liam Morland’s picture

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

sashkernel’s picture

But what's the %profile.... token for. Isn't it supposed to pull values from user profile, or am I wrong?

Liam Morland’s picture

Project: Webform Tokens » Webform
Version: 7.x-1.1 » 7.x-3.x-dev
Category: bug » support

Yes, 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.

cmejo’s picture

I'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

Liam Morland’s picture

Try [webform:val-first_name]

cmejo’s picture

Thank 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?

Liam Morland’s picture

You need Webform Tokens module for tokens of that style to work. The development version has just recently been updated to work with Webform 4.

cmejo’s picture

@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?

Liam Morland’s picture

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

cmejo’s picture

It 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!

Liam Morland’s picture

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

cmejo’s picture

@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?

Liam Morland’s picture

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

tknospdr’s picture

Adding my comment that %profile[key] does not work for me either.

Per Webform's setup page:

Special tokens
%profile[key] - Any user profile field or value, such as %profile[name] or %profile[profile_first_name]

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

tknospdr’s picture

Version: 7.x-3.x-dev » 7.x-3.8
Priority: Normal » Major
loopy1492’s picture

Profile 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?

loopy1492’s picture

I 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

loopy1492’s picture

I used this.

http://drupal.org/node/1308722#comment-5979152

Not elegant, but my only option at the moment.

quicksketch’s picture

Hi @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.

quicksketch’s picture

Status: Active » Closed (fixed)
tknospdr’s picture

Issue summary: View changes

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

tknospdr’s picture

Version: 7.x-3.8 » 7.x-3.20
Status: Closed (fixed) » Active
quicksketch’s picture

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.

Webform 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?

tknospdr’s picture

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

quicksketch’s picture

Version: 7.x-3.20 » 7.x-4.0-alpha6

Yeah 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).

Liam Morland’s picture

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

panditvarun20’s picture

I also having same problem. Can anyone help me from this. Should I write any php code for this ?

quicksketch’s picture

Priority: Major » Normal
Status: Active » Fixed

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

magpie5212’s picture

Shouldn't the help text under Token Values be changed to reflect this?

Status: Fixed » Closed (fixed)

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