I created a system plugin with the onContentPrepareForm() method to load an entire module options form, and the form loads correctly, but will not save the entered data.

The coding


public function onContentPrepareForm($form, $data) 
  if( $form->getName() == 'com_modules.module' && $data->module == 'mod_stuff' ) {
    $form->loadFile('mod_stuff', false);

The override form mod_stuff.xml

<?xml version="1.0" encoding="UTF-8"?>
<fields name="params">
    <fieldset name="basic">
        <field type="textarea" name="thetextarea" label="Write Stuff" />
        <field type="text" name="thetext" label="Just Write" />

The module's manifest XML mod_stuff.xml


The manifest just serves as an item to register the module but all files are sourced from the plugin. The installation process of the plugin creates the module folder and registers to the DB _extensions table

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1" client="site" method="upgrade">
    <author>The author</author>
    <copyright>Copyright here</copyright>
    <license>GNU General Public License stuff</license>
    <description>the detail</description>



<?php defined('_JEXEC') or exit('stuff');

include JPATH_PLUGINS.'/system/dropmods/mods/mod_stuff.php';

What has worked

If I use a subform method in the module's manifest file modules/mod_stuff/mod_stuff.xml to load the override file, the data saves correctly, however the subform process create additional parent object name settings and it poses a bit of challenge.

    <fields name="params">
        <fieldset name="basic">

What's required to allow the plugin override form to save the data?

1 Answer 1


There's a quirk when using onContentPrepareForm event. Data may not always be available and sometimes it can be an array instead of an object. You can confirm this by inspecting PHP error log. You should find entries like these:

PHP Warning: Attempt to read property "module" on array in C:\wamp\www\joomla-cms-3\plugins\system\example\example.php on line 31

PHP Warning: Undefined property: stdClass::$module in C:\wamp\www\joomla-cms-3\plugins\system\example\example.php on line 31

To workaround the issue, get data from input if it's not set and cast it to object:

$data = (object) ($data ?: $this->app->input->get($form->getFormControl(), [], 'array'));
  • There is no error thrown and no error logs to see. The work-around didn't deliver the data, still an empty object. It seems $data is only scanning the plugin's scope on save
    – Nadal
    Jul 24, 2021 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.