Pre-Filling Ninja Forms Fields with Logged-In User Data
Problem:
How do I automatically pre-fill fields in a Ninja Forms form with logged-in user data like first name, last name, and email?
Or
How can I pre-fill Ninja Forms fields based on logged-in user information in WordPress?
Solution:
You can easily auto-fill fields in Ninja Forms based on the logged-in user’s meta data using built-in merge tags or a custom filter in WordPress.
Method 1: Using Merge Tags
- Go to Ninja Forms > Forms and edit your form.
- Select the field you want to auto-fill (e.g., First Name, Email).
- In the Advanced Settings section, find the “Default Value” option.
- Use merge tags like:
{user_meta:first_name}
for first name{user_meta:last_name}
for last name{user:email}
for email{user_meta:your_custom_meta_key}
for custom user meta fields
Method 2: Using a Custom Filter (For Advanced Logic)
If you need more flexibility, you can use the ninja_forms_render_default_value
filter:
This approach works seamlessly for automatically pulling in user data into your forms.
Conclusion:
Using either merge tags or custom code, you can easily set up Ninja Forms to pre-fill fields with logged-in user information, making your forms more user-friendly and efficient.