How to get the current user

Lets explore how you automatically populate a text fields with the current users details

Updated over a week ago

Team Forms automatically tracks the user who submits each response, however in some situations it may be helpful to display the users details inside the form itself. There are several way to achieve this which are outlined in this article

User Component

The easiest way to display the current user in your form is using the user component and configuring the default value to the current user. This can be done by following the steps below:

  1. Drag and drop a user component into your form

  2. Disable the component to prevent modifying it value

  3. under the data tab set the default value to "current user"

Calculated Value

You can use Team Forms calculated values feature in conjunction with JavaScript to automatically populate a component with the logged in users details. To do this Team Forms provides a special function called TF_USER() which will return the users details including there name, email and id. Lets use this function in the example below to populate a text field with the users email.

  1. Drag an drop a text field into your form

  2. In the components setting navigate to the data tab and expand the "calculated value" section. This will expand a code block allowing you to write your own Javascript.

  3. Paste the one of the javascript expressions below in the code block to automatically set the text field value.
    To populate email:

    value = TF_USER().email

    To populate the name:

    value = TF_USER().name

    Name

  4. In the display tab scroll down and check the "disable" option to prevent users from changing the value.

Did this answer your question?