Closed (fixed)
Project:
Webform
Version:
7.x-4.0-alpha3
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Jul 2012 at 08:30 UTC
Updated:
14 Aug 2012 at 14:11 UTC
I already posted this on the forums but I figured this is probably the better place to ask this.
If one has a webform that is open to anonymous users, which asks information that is known for registered users (age, gender, ...), is it possible to remove this question from the display and/or fill in the value automaticallty, if the user filled the corresponding field in their profile?
Is this possible at all? How would you recommend me to do this?
Comments
Comment #1
quicksketchYou can do this by using the 4.x branch, which includes the typical Drupal token support so you could set the default value of fields to something like [user:field_first_name], [user:field_age], etc. based on the fields you have set up on your site.
Comment #2
P3t3r commentedAnd is there any way to process these fields first, e.g. compute their age from their birthday?
Comment #3
quicksketchYou could create your own tokens with the Token API through hook_tokens() and hook_token_info(). Webform itself doesn't provide any special post-processing on default values.
Comment #4
P3t3r commentedThis works for text fields, but it seems that select lists do not allow a default value in 4.0 alpha3. Is this intentional, and if so, why? It seems perfectly reasonable to allow a default key on select fields... is this a bug, or an intentionally missing feature?
Comment #5
quicksketchSelect lists definitely allow default values. Do you have Options Element installed? It hides the default value field since it displays them as radio buttons/checkboxes. You have to click the "Manual" link below the options element to set a default value that is a token.
Comment #6
P3t3r commentedIndeed, the problem was indeed with Options Element.
So there is still some small incompatibility. Well, not that Options Element is a necessary module anyway.
I'll see if I can get the tokens working and report back here when finished (currently there's still a problem).
Comment #7
P3t3r commentedIt works now. :)
If anyone want to try it, I will add here for future reference that profile fields do not appear automatically in $user, you have to execute
and then grab them from $user_data.
Comment #8
gopisundar commented@P3t3r
Can you please tell me where to add this line?
Comment #9
P3t3r commented@gopisundar: I recommend reading the basic tutorial on creating modules, and this tutorial on making new tokens. Then, after adding new fields to your profile, the natural thing to do would be (as in the token tutorial) to write in your modulename_tokens() function:
however, that should be
instead.