Auto Filled Fields based logged is User

Dear All,
Please i need some help.

How to make that some fields are auto filled based from the logged in user?

Example:

John is from Alaska
Robert is from California

in the forms have field with name LOCATION

  • When John logged in, field LOCATION auto filled to Alaska
  • When Robet logged in, field LOCATION auto filled to California

Thank you for your help.

For a logged in user, you can use the user merge tag to set the ‘Default Value’ for form fields. So for your users, let’s assume you stored their Location in a user meta field called ‘location’. When the user logs in, you can use any of that information from their user meta (profile.) If you want to populate a field in the form with their location, use this merge tag as “Default Value” for the field:

{user:location}

If you had information about their favorite restaurant stored in a user meta field with a meta key of ‘fav_restaurant’ you could use this merge tag for default value of a field to retrieve and show that data:

{user:fav_restaurant}

Let us know if you need more assistance with that process.

1 Like

Hi Chris,
Sorry, I still do not understand from your explanation … sorry I do not understand about “merge tag”.

Can you give an example of how to use it?

sorry in advance because I am still a newbie.

Sure. First, take a look at this documentation:

That explains the merge tag usage.

This is a merge tag:

{user:location}

You can use that merge tag as the “Default Value” for any field in the form builder. Go to the Advanced Tab of the field, and enter that merge tag in the Default Value input and save the form.

When a logged in user visits the page with the form on it, that field will be pre-filled with the information stored in their profile (user meta) with a meta key of location. If you have information stored with other meta keys, use those keys in place of location in my example.

Let us know if you have any other questions.

Hi Chris,
did you mean their profile in database WP wp_users? i cannot find column location.

so I just use the column user_activation_key, although I have to input it one by one.

{user:user_activation_key}

That’s not right at all…

No, the wp_usermeta table. There will be a column meta_key. That is what you use in the user merge tag, like this:

{user:meta_key}

Here’s some wp_usermeta for one user:

To get location into a form field, I would use this merge tag as “Default Value” (on the Advanced tab):
default value

When the form is shown, the information from the logged in user’s profile (wp_usermeta) is shown in the form field already:
form

Let me know if you need more assistance with that.