Error en copy join forms

elkekas

New Member
Subject: Bug in form.php (line 1798) when counting non-array data in repeat groups

Issue Description:
There is an issue in components/com_fabrik/models/form.php at line 1798, where the code assumes that the value retrieved from $this->formData[$smallerElHTMLName] is always an array. However, in some cases, the value can be a string or even null. This leads to a TypeError in PHP 8+ because count() can only be used on arrays or objects implementing the Countable interface.

Problematic Code (line 1798):
Code:
$repeatGroup = count($this->formData[$smallerElHTMLName]);
If $this->formData[$smallerElHTMLName] is not an array, this will trigger an error in PHP 8:
TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

Proposed Solution:
Add a validation to check whether $this->formData[$smallerElHTMLName] is an array before calling count(). If it is not an array, handle it as a single value or consider it empty if the value is null or an empty string.

Corrected Code:
Code:
if (isset($this->formData[$smallerElHTMLName])) {
    $fieldData = $this->formData[$smallerElHTMLName];

    if (is_array($fieldData)) {
        $repeatGroup = count($fieldData);
    } else {
        $repeatGroup = !empty($fieldData) ? 1 : 0; // 1 if data exists, 0 if empty
    }
} else {
    $repeatGroup = 0; // Default if the key does not exist
}
Explanation of Fix:

  1. Use isset() to ensure the key exists in $this->formData.
  2. Check if the value is an array using is_array().
  3. For non-array values, check if the value is non-empty (!empty()) to decide whether to consider it as one repetition (1) or none (0).
Location:
File: components/com_fabrik/models/form.php
Line: 1798

This fix ensures compatibility with PHP 8+ and avoids errors when handling non-array values in repeat groups.
 
Thank you!

I have created a pull request in the Git repository as requested.

Please let me know if any additional changes or clarifications are needed. I’ll be happy to assist!

Best regards,
 
Back
Top