Display Custom Fields on Profile Page

Discussion forum about Anuko Time Tracker
Post Reply
bigredthelogger2021
Posts: 4
Joined: Mon Mar 08, 2021 10:44 pm

Display Custom Fields on Profile Page

Post by bigredthelogger2021 » Tue Mar 09, 2021 12:18 am

I would like to display all of the user specific Custom Fields on the Users Profile Page. I figured it was as simple as the below but nothing displays. Any suggestions?

Code: Select all


  {if $custom_fields && $custom_fields->userFields}
    {foreach $custom_fields->userFields as $userField}
      {$userField['label']|escape}
    {/foreach}
  {/if}


bigredthelogger2021
Posts: 4
Joined: Mon Mar 08, 2021 10:44 pm

Re: Display Custom Fields on Profile Page

Post by bigredthelogger2021 » Tue Mar 09, 2021 12:32 pm

The following code displays the custom fields but not the data within them.

Code: Select all


{if $custom_fields && $custom_fields->userFields}
  {foreach $custom_fields->userFields as $userField}
        {assign var="control_name" value='user_field_'|cat:$userField['id']}
  <tr class = "small-screen-label"><td><label for="{$control_name}">{$userField['label']|escape}:</label></td></tr>
  <tr>
    <td class="large-screen-label"><label for="{$control_name}">{$userField['label']|escape}:</label></td>
    <td class="td-with-input"> TBD by Jason</td>

  </tr>
  <tr><td><div class="small-screen-form-control-separator"></div></td></tr>
  {/foreach}
{/if}


bigredthelogger2021
Posts: 4
Joined: Mon Mar 08, 2021 10:44 pm

Re: Display Custom Fields on Profile Page

Post by bigredthelogger2021 » Tue Mar 09, 2021 2:59 pm

It looks like the following code is what's needed but the value of each custom field is always null.

I am trying to have a spot for employees to see how many vacation hours they are allowed and then they can compare that against the report.

Code: Select all


foreach ($custom_fields->userFields as $userField) {
  $control_name = 'user_field_'.$userField['id'];
  $userCustomFields[$userField['id']] = array('field_id' => $userField['id'],
    'control_name' => $control_name,
    'label' => $userField['label'],
    'type' => $userField['type'],
    'required' => $userField['required'],
    'value' => $custom_fields->getEntityFieldValue(CustomFields::ENTITY_USER, $user_id, $userField['id'], $userField['type']));
    
    print_r($userCustomFields);
}


bigredthelogger2021
Posts: 4
Joined: Mon Mar 08, 2021 10:44 pm

Re: Display Custom Fields on Profile Page

Post by bigredthelogger2021 » Tue Mar 09, 2021 4:03 pm

I figured it out for anyone else needing help.

print_r($userCustomFields[1]);

wrc
Posts: 312
Joined: Tue May 25, 2010 8:30 pm

Re: Display Custom Fields on Profile Page

Post by wrc » Tue Mar 09, 2021 6:38 pm

bigredthelogger2021 wrote:
Tue Mar 09, 2021 12:18 am
I would like to display all of the user specific Custom Fields on the Users Profile Page.
Is this profile_edit.php page or some other page?

Post Reply