Contact form 7: Auto fill fields for Logged In user information
As we know we mostly use contact form 7 plugin for forms in WordPress websites.
Generally contact forms will always be there at Contact us page of the website.
it consists of few mostly used fields like:
- Name
- Phone Number
- Message/Comments
User normally fill this data and then click on submit. Mail will sent to the mail id as per the form settings in admin.
We are discussing the situation when a user is logged in to the website and want to fill this form. The process is same for him as for other users.
now we are trying to minimize efforts for a logged in user to save his time. If a user is logged in to the website then we already have few details
for that user like their name, email etc.
So, it is better or more professional to show a form already filled with available details for a logged in user. All the fields which we already have for a user, we need to automatically populate the values of these fields and then show to the user.
Below is the example to already fill a user’s name which we are already have:
[text* name default:user_display_name] //It will already fill user's display name to the name field
For email we write below short-code :
[email* email default:user_email] //It will already fill user's email to the email field
‘
We have several fields in WordPress for a logged in user, which we can use to auto fill. Below is the list:
User’s login name – default:user_login
User’s email address – default:user_email
User’s site address – default:user_url
User’s first name – default:user_first_name
User’s last name – default:user_last_name
User’s nickname – default:user_nickname
User’s display name – default:user_display_name
We can use any details of the above mentioned as per our requirement.
Note: If you are writing placeholder in your short-code then write this default code before it to make it working fine.
Just look at the attached images, one is having the short-code to generate a form with all possible options for name and email.
Another Image is showing the output from that short-code for a logged in user. You can use this feature just as per the short-code image.
Form will work same as it was for non logged in users.
It is just a smart effort to minimize logged in users efforts. This will definitely increase users engagement to your website.
Great useful tip thanks.
A suggestion though, the combination of 0px left hand padding (unless on 1920 full width) + the social icons on this page give it a UX 1 star..
Now how do you get it to send to that user email? The Mail / To: field?
Never mind. Didn’t enter the email field right. Should be whatever you call the field. EG: [your-email]
Duh!!
Great tip right here. Will try it today
is possible to take all of the user fields? like address or custom field
Great job Dude!!!
Only one thing… it doesn’t work with other metakey.
Example if You have Wp-member and You try to add some metafield filled during registration form this field is unreachable…
Hope to find how to figure out.
Warm regards
Axl
I wonder if you could help me by expanding on this a little further.
A client has asked to auto fill a form with logged in user details, So for the most of the form, name and email covers it.
However, the client have asked if it’s possible for users to provide a telephone number and business name when they registr to the site and then the contact form can also pull in these details?
Is this possible with Contact Form 7 in a round-about way?
I thought found the answer using the following link:
https://coderwall.com/p/g72jfg/adding-a-phone-numer-field-to-wordpress-user-profile
Which works by allowing me to create the extra telephone and business name field, but I can’t seem to get Contact Form 7 to pull in this data. Help is much appreciated.
Thank you in advance.
“contact form 7 telephone” is plugin to create a country telephone drop-down list with country flags using Country telephone Field Contact Form 7.