Can you pre populate fields based on a logged in user... Say you have a support form so based on the user that is logged into your site.. The name and email field would be pre populated based on the user that is logged in to wordpress??
Thanks Scott
Can you pre populate fields based on a logged in user... Say you have a support form so based on the user that is logged into your site.. The name and email field would be pre populated based on the user that is logged in to wordpress??
Thanks Scott
Yes. There are two ways to do this. If it's information on the user that is logged into the site you may be able to simply use available merge tags and the default value option on fields it's available for.
Merge tags are documented here:
http://www.gravityhelp.com/documentation/page/Merge_Tags
So if you want to populate the email field with the email of the user that is logged in and filling out your form, you would:
- Edit the email field on your form
- Select the advanced tab
- In the default value set it to {user:user_email}
- Save your form
Now that field's default value will be set to the email of the user viewing the form if they are logged in.
If it's information that can't be output via available merge tags then you can always use some custom PHP and dynamically populate the field. Here is some information on how to dynamically populate fields:
http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population
Ah .. cool.. I see that for email but not name... Name has a different option... (allow field to be populated dynamcially via short code query string or hooks.... is the name not as easy?
I tried adding this in the name field {user:user_login}
The email field is working :) Awesome... supplies a drop down to select from but not the name fields :(
i tried with {user:first_name} in the advanced name field and nothing happen, but if i use a simple line text field it's ok all work fine;
I have the same problem; is it possible to populate the advanced name field from the WordPress user data?
You'd have to know what the user meta key name is for the the user meta you want to display using the merge tag. It's {user:key} and the key is the user meta key name for the data you want to return.
Hi guys,
Here is a more advanced solution that allows you to use Gravity Forms dynamic population to populate any user meta in any field that support dynamic population:
I'm having the same issue as raffav. I added the name field and set it so it's first name/last name. Checked the box in the advanced tab for allowing the field to be populated dynamically. I added {user:first_name} in the first name and {user:last_name} in last name from what I found here:
http://www.gravityhelp.com/documentation/page/Merge_Tags
It's displaying the email address correctly for a logged in user but the name fields are blank.
Just for the heck of it I replaced the first name meta key with {user:user_email} and the first name field is still blank when a logged in user looks at the form.
Hi gchinola,
The more advanced method does not user Merge Tags to populate; it is powered by the custom snippet provided in the thread I linked to. After implementing the snippet, you're dynamic population parameters should look like this:
I was trying the non-advanced method which I think is supposed to work. If it's not working, I'll give the advanced method a shot, I just didn't think I needed to.
I understanding the confusion. A couple things to keep in mind. The "Enable Dynamic Population" option does not support merge tags. The "Default Value" option supports some merge tags. You'll notice that on some field types (including the "Name" field), there is no option to specify a default value. This means in order to populate a default value you'll need to use dynamic population.
The advanced method I linked to uses dynamic population to populate the user meta based on your dynamic population parameters and a little configuration in the code. Don't be daunted by it! It's easier than you think. :)
Hey, I think the users here are trying to point out a recent bug.
Merge tags such as {user:first_name} USED TO work just fine as a default value, but they are not working any more. This is a semi-recent phenomenon. It has broken a number of my forms that were working just fine before.
Ended up here trying to pre populate some formfields. Could not get it to work.
Now I read mr. g0shu4 message, here above!
Could it be that something changed and the code is not working anymore?
I am on Wordpress 3.3.1 (most recent as of now).
Can someone please confirm this. And is there a workarround??
Until recently, {user:display_name} and {user:user_login} were working anywhere I put them in the form and notification area. I thought it was user error in forms that are already live.
I'm building a new form today and notice now they are not working at all.
Oh, and I'm using WP 3.3.1 and GF 1.6.2
Better continue this over here:
http://www.gravityhelp.com/forums/topic/bug-report-pre-populate-not-working
We have a fix for the user merge tags no longer pre-populating the fields. This appears to have happened with WP 3.3. Because we have a lot of new features coded for Gravity Forms version 1.6.3, we are providing this fix as version 1.6.2.1.1 and those who need it should email me directly at the email address on my user profile and mention this topic. I will email you the file.
Thanks!
I am closing this ticket. Please use http://www.gravityhelp.com/forums/topic/bug-report-pre-populate-not-working instead for issues with this discovered bug.