Get User Name on Form

Jennifer Brown asked on October 11, 2016 20:15

This should be simple but I just can't figure it out. I blame the rise of clown sightings. How do I get the logged in username to display in an email once they have submitted a form?

Recent Answers


Joshua Adams answered on October 11, 2016 20:20

You can add a field onto your form that takes in the users email by default. Make sure not to display the field, and have the default value be the current users userid or their email address.
{% CurrentUser.Email %} or {% CurrentUser.UserID %}, if using the userid, you will have to fetch the email through a macro, but that will make it a bit more flexible, and also account for when users change their email, may or may not come into play or be necessary. Email will be easier to work with, so if not comfortable with macros, I would suggest sticking with that for now.

Then in your email, reference the new field, just like the other fields.

2 votesVote for this answer Mark as a Correct answer

Jennifer Brown answered on October 11, 2016 20:47

Thank you! That got the information I needed; however, when I add {% CurrentUser.UserID %} as the default value and click Save, it adds a hashtag and becomes {% CurrentUser.UserID #%}. Do you know why this is happening?

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 11, 2016 21:06

Thats a security parameter that kentico uses. It shouldn't stop the macro from resolving. By default, it "signs" the macro for security. Is your macro not resolving?

0 votesVote for this answer Mark as a Correct answer

Jennifer Brown answered on October 11, 2016 21:31

I see what I did, I didn't click the > before entering the value. Thanks!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.