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),

  1. The form loads
  2. Existing data is retrieved/loaded
  3. 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)

    [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
    $form->loadFile('customfields2', false);
    return true;
    // Conditional loading does everything as expected EXCEPT:
    // It does not save it #__categories.params
    if($pse=='P') {
        $form->loadFile('customfields1', false);
        return true;
        return true;
    }elseif($pse=='E') {
        $form->loadFile('customfields3', false);
        return true;
        return true;

As posted, the question is basically unanswerable because it was due to a coding error that didn't seem relevant to the question. My first inclination was to delete the question, but I thought the reason for the coding error was interesting enough for anyone that might encounter a similar problem.

In short, my code to determine which type of form I wanted to load was referencing $data, and was quietly getting the following error when Joomla called the plugin function during the save process:

Notice: Trying to get property of non-object in myplugin\myplugin.php on line 12

Presumably, this was preventing the form from loading somewhere upstream, and Joomla simply didn't know what to do with the form data, so dropped it.

The reason for this error occurring only during the save is that $data being passed to the onContentPrepareForm function is empty when called during the save. This doesn't seem "right" to me, thus my assumption that it was there, but nonetheless, that's why there was a warning notice fired, which caused the function to fail, and ultimately the form data to be lost.

| improve this answer | |

Your Answer

