Subform Custom Filed Not Displayed On User Profile View - Question | JoomShaper
🎃 Halloween Sale is Live! Get 35% OFF on all plans. Sale ends soon! Get Offer

Subform Custom Filed Not Displayed On User Profile View

DM

Diego Mello

SP Page Builder 7 months ago

Hello,

I have a Languages Subform created for user profile, and when a user view his profile (option=com_users&view=profile), even after making the required selections on the Languages Subform, nothing is dislayed and my users are getting confused because they think their profile is not being correctly saved.

Can you help? Diego

0
6 Answers
Atick Eashrak Shuvo
Atick Eashrak Shuvo
Accepted Answer
Support Agent 7 months ago #187201

Apologies for the inconvenience. I have reviewed your website and noticed that the profile system in use is not part of Joomla's core functionality or JoomShaper's extensions. Since this issue appears to be related to a third-party extension, I recommend reaching out to the extension's developer for further assistance.

Thank you for your understanding.

Best regards

0
DM
Diego Mello
Accepted Answer
7 months ago #187219

Dear Atick,

I am not sure I undestand what you mean. The profile page is joomla's standard one. It show Joomla's user profile with custom fields and the subform is joomla's stndard. This subform is composed of:

A Subform filed, two list field and one checkbox field. All of them are standar joomla fields.

I have Membership Pro on my site, but I don't use that component for the profiles.

As I mentioned, the issue is on option=com_users&view=profile which is a joomla standard view.

Diego

0
DM
Diego Mello
Accepted Answer
7 months ago #188491

Hello guys,

It is a bit frustrating to have the issue open withut an answer. So I asked a developer to check the code and find a solution, below are his edits on the default_custom.php file.

The Sole Correction:

The fix applied was to change the name from subform_rows to fieldparams->subform_rowin this section:

-if (isset($customFields[$correctFieldName]->subform_rows[$row_number]) && is_array($customFields[$correctFieldName]->subform_rows[$row_number])) {
+if (isset($customFields[$correctFieldName]->fieldparams->subform_row[$row_number]) && is_array($customFields[$correctFieldName]->fieldparams->subform_row[$row_number])) {
-   foreach($customFields[$correctFieldName]->subform_rows[$row_number] as $subfieldDefinition) {
+    foreach($customFields[$correctFieldName]->fieldparams->subform_row[$row_number] as $subfieldDefinition) {

Here's the explanation of all the changes made to the default_custom.php file to correctly render subform custom fields in the Joomla user profile:

Overall Goal:

The primary goal was to fix the rendering of subform custom fields in the Joomla user profile view. The original code was not displaying the subform data correctly, only showing the subform field's title, but not its inner field values and titles.

Key Issues Addressed and Corrections Made:

1. Incorrect Subform Identification:

  • Problem: The initial code incorrectly identified subform fields. It assumed that any field with an array or object value was a subform, which is not true.
  • Solution: A more accurate check was implemented using $isSubform:
$isSubform = false;
if (is_array($field->value) && count($field->value) > 0) {
    $firstKey = array_key_first($field->value);
    if (is_object($field->value[$firstKey]) && get_class($field->value[$firstKey]) === 'stdClass') {
        $isSubform = true;
    }
}

This new code checks if the $field->value is an array and if its first element is a stdClass object. This structure is characteristic of Joomla subform data.

2. Incorrectly Using $field->fieldname:

  • Problem: The code was trying to use $field->fieldname to access the subform definition in $customFields. However, for subform fields, $field->fieldname is always "row" and therefore useless for this purpose.
  • Solution: We switched to using $field->name and created a helper function extractFieldName() to parse it:
function extractFieldName($fieldName)
{
    $parts = explode('[', $fieldName);
    $lastPart = end($parts);
    $lastPart = str_replace(']', '', $lastPart);
    return $lastPart;
}

This function correctly extracts the subform name (e.g., "languages") from the $field->name string (e.g., jform[com_fields][languages]).

3. Incorrectly Accessing Subform Definitions:

  • Problem: The code incorrectly tried to access subform field definitions, first with subform_fields and latter with subform_rows. These properties do not exist.
  • Solution: The code was corrected to access the subfield definitions using the correct structure fieldparams->subform_row:
 // Check if the subform definition exists
 if (isset($customFields[$correctFieldName]->fieldparams->subform_row[$row_number]) && is_array($customFields[$correctFieldName]->fieldparams->subform_row[$row_number])) {
     foreach($customFields[$correctFieldName]->fieldparams->subform_row[$row_number] as $subfieldDefinition) {
         if($subfieldDefinition->name == $key){
             $subfieldTitle = $subfieldDefinition->title;
             break;
         }
      }
 }
  • This is the fix.
    • fieldparams->subform_row is the correct path to get the information of each subform.
    • The foreach will iterate through each subfield definition.
    • Inside the loop, it will check if $subfieldDefinition->name is equal to $key, and get the title, if it matches.

4. Incorrectly Prioritizing $customField->value:

  • Problem: For subforms, the code was incorrectly trying to use $customField->value for the subform field's data, where it was actually in $field->value
  • Solution:
    • The code now correctly uses $field->value to access the data of the subform.
    • For other fields, it continues using $customField->value.

5. Missing the extra level:

  • Problem: The code missed the extra level inside the subform_row.
  • Solution: The code now correctly navigates this extra level.

6. Other Minor Improvements:

  • Better error handling (e.g., "Error: Invalid data format...").
  • Improved comments for clarity.
  • Code formatting and consistency.

In Essence:

The main improvements were:

  1. Correctly identifying subform fields by checking the structure of $field->value.
  2. Using $field->name and extractFieldName() to correctly look up definitions in $customFields.
  3. Correctly using fieldparams->subform_row to access subform field definitions.
  4. Using $field->value to access the data.

Impact:

These changes result in the correct rendering of subform custom fields in the user profile view, including:

  • Displaying all subform rows and their data.
  • Displaying the correct labels/titles for each subform field.
  • Avoiding any PHP errors or warnings.
  • Rendering other custom fields correctly.
0
Atick Eashrak Shuvo
Atick Eashrak Shuvo
Accepted Answer
Support Agent 7 months ago #188559

Hello Diego,

Please check if this functionality works correctly with the default Joomla template. If the issue persists, it is not related to our template, and the configuration may need to be reviewed. Additionally, since you have replaced our template code with your custom modifications, we are unable to provide support for those changes. We recommend reaching out to the author of the code for further assistance.

Best regards

0
DM
Diego Mello
Accepted Answer
7 months ago #188654

Thank you for your reply, Atick.

It deoes work on Cassiopeia and without any changes on the code.

We just changed your template's code because it doesn't show Subform Data correctly.

Best regards, Diego

0
Atick Eashrak Shuvo
Atick Eashrak Shuvo
Accepted Answer
Support Agent 7 months ago #188735

Hello Diego,

When I switch the template to Cassiopeia, I am unable to see the Subform data. I might be missing something. Could you share a screen recording showing how it works with the Cassiopeia template? This will help me better understand the issue.

Best regards

0