YesNo Element Plugin - Undefined Array Key Warning (Repeat Groups in Tab Tmplt Form View)

beatty_t

New Member
Hi All!

The warining message is:
Warning: Undefined array key "" in /www/wwwroot/centralparking.ca/plugins/fabrik_element/yesno/yesno.php on line 307

This is not an urgent request as it is only a warning that is generated when Joomla's Global Configuration Server settign for Error Reporting is set to "Maximum" AND the following conditions are present:

1. The form is constructed of an initial list that is joined to one or more other tables (lists) where a YES/NO element is included in one of the joined lists.
2. The group(s) with the Yes/No element associated is/are joined to the main list as (a) repeat group and the minimum allowed number of repeats is set to a value of 0f 0 "zero" (defined in the Group Admin Form within the administrator area of your site).
4. You save a form and do not include a row for that repeat group (i.e. keep the min repeat group row count at 0 "zero" thus no records in the repeat group's table have a parent_id matching your main list's record id).
5. Edit the main list's record (within the administration side of the site).
6. Not sure if this matters, but the form template used is bootstrap_tabs

I found that the following is able to suppress the warning, but it isn't pretty...

if(!empty($value)) {
$label = $options[$value]->text;
} else {
$label = "";
}


So, if it happens to be the case that $value is empty, it'll skip trying to set the $label as $options[$value]->text and just set $label to empty... It doesn't cause an issue in this scenario because I'm not saving any record for that repeat group anyway and I can (within edit mode) add a row for that repeat group later, save, and go back into the same record with everything saved correctly.

What confuses me however, is the condition where this all happens. From what I'm understanding, the element in the repeat group is being considered a "Read Only" element (which isn't the case within the element's settings). Because I'm in the "Edit" form view, $this->inDetailedView === true shouldn't apply. So that suggests to me that the YES/NO element (when not visible because there isn't any repeat group row) must be satisfying $this->isEditable() === false, but I don't think that should be the case...

if ($this->isEditable() === false || $this->inDetailedView === true) {
$value = $this->getValue($data, $repeatCounter);

if(!empty($value)) {
$label = $options[$value]->text;
} else {
$label = "";
}

return self::getReadOnlyOutput($value, $label);
}


I had added a thread about a few element plugins that were displaying warnings when Joomla's Global Config -> Server -> Error Reporting setting was set to Maximum. Like the above, the previous thread's issue related to empty values returning warnings where functions like trim() or htmlspecialchars() were being used and require non-empty(null) strings. So, if a user saved a form and one of the input fields was a element plugin type that used trim() or htmlspecialchars() when being prepared for display in the form, but didn't have a value entered for that field when the form record was originally saved, in editing, that same record (while fabrik was preparing the input field content for display), would trigger warning message. This is the thread: Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated. Within this thread, achartier kindly provides some fix suggestions (and is including them in next releases of Fabrik). This particular issue might be included as part of the fixes within next releases...

Thanks

Have a good one all!
 
The first issue is easily corrected. I suggest the following:
Code:
            $label = !empty($value) ? $options[$value]->text : "";
As for the second issue I don't suppose I could get a backup of your site so I can test it could I?
 
Can confirm that achartier's script resolves the issue (much nicer and cleaner than how I put it together) and thanks a bunch!

I'll see about getting a backup put together for you (I'll need permission from the owner of the site). Would an Akeeba *.zip file work (if I do get an okay)?

Thanks


Travis
 
Yes, and Akeeba backup would be great and instructions on haw to recreate. If you put the backup in a dropbox you can pm me the details
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top