I'm completely baffled! I'm trying to load Custom Fields to a Category as I've successfully done in the past, and explained in this question/answer. It works as expected until I try to load a different form depending on some criteria about the category.
In both cases (conditionally and unconditionally),
- The form loads
- Existing data is retrieved/loaded
- When saving, $_POST contains the custom data
However, if a form is loaded conditionally, it loads as expected, but doesn't save it. Not only does it not save, but the data that was originally loaded is no longer there!
My first thought was that a default form name was required, but it was able to determine the correct form to load the page and parse the data to post correctly, so I'm a a dead standstill on what could be wrong.
$_POST
variable when saving: (in both cases)
Array
(
[category_layout] =>
[image] =>
[my_pse] => P
[my_extra1] => 1
[my_extra2] => 22
[my_extra3] => 333
)
Code from onContentPrepareForm
The if(true)
test is simply to easily toggle between the two blocks of code.
if(true) {
// Unconditional loading does everything as expected:
// It Saves/Retrieves to/from #__categories.params
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('customfields2', false);
return true;
}else{
// Conditional loading does everything as expected EXCEPT:
// It does not save it #__categories.params
if($pse=='P') {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('customfields1', false);
return true;
}elseif($pse=='S'){
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('customfields2', false);
return true;
}elseif($pse=='E') {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('customfields3', false);
return true;
}else{
return true;
}
}