Skip to main content
deleted 15 characters in body
Source Link

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the questions on the form being categories i.equestion's associated field.

<input name="fields[{{ categoryquestion.fieldName }}]">

This works nicely but I am looking to pre-populate this input with a value if the user has previously provided and saved this info but I'm having trouble figuring out how to combine the field name with currentUser.

My first try was:

{% set fieldName = categoryquestion.fieldName %}
{{ currentUser.fieldName }}

But that returns the following error:

Craft\UserModel and its behaviors do not have a method or closure named "fieldName".

Any help would be greatly appreciated

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the questions on the form being categories i.e.

<input name="fields[{{ category.fieldName }}]">

This works nicely but I am looking to pre-populate this input with a value if the user has previously provided and saved this info but I'm having trouble figuring out how to combine the field name with currentUser.

My first try was:

{% set fieldName = category.fieldName %}
{{ currentUser.fieldName }}

But that returns the following error:

Craft\UserModel and its behaviors do not have a method or closure named "fieldName".

Any help would be greatly appreciated

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the question's associated field.

<input name="fields[{{ question.fieldName }}]">

This works nicely but I am looking to pre-populate this input with a value if the user has previously provided and saved this info but I'm having trouble figuring out how to combine the field name with currentUser.

My first try was:

{% set fieldName = question.fieldName %}
{{ currentUser.fieldName }}

But that returns the following error:

Craft\UserModel and its behaviors do not have a method or closure named "fieldName".

Any help would be greatly appreciated

Source Link

Variable for User Field

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the questions on the form being categories i.e.

<input name="fields[{{ category.fieldName }}]">

This works nicely but I am looking to pre-populate this input with a value if the user has previously provided and saved this info but I'm having trouble figuring out how to combine the field name with currentUser.

My first try was:

{% set fieldName = category.fieldName %}
{{ currentUser.fieldName }}

But that returns the following error:

Craft\UserModel and its behaviors do not have a method or closure named "fieldName".

Any help would be greatly appreciated