You can override the JForm class with your own version in one of two ways:
System Plugin
Via a System plugin that triggers onAfterInitialise():
/**
* Registers core library overrides.
*
* @return void
*/
public function onAfterInitialise()
{
// Override /libraries/joomla/form/form.php
JLoader::register('JForm', JPATH_LIBRARIES . '/core-overrides/joomla/form/form.php');
}
However, by the time onAfterInitialise() is called many core classes have already been initialized and so this method wont work. I don't know if JForm falls into this category or not. You may need to try it and find out. If it does fall into that category your only route is via a core hack...
Core Hack
First, obviously, core hacks are evil. But I've yet to find a working solution when the plugin method doesn't work (when the class has been initialized before onAfterInitialise() is called).
Modify /ROOT/index.php and/or /ROOT/administrator/index.php (depending on if you need this modification for back-end or front-end executions). Put this code:
require_once JPATH_LIBRARIES . '/core-overrides/coreOverrideAutoloader.php';
spl_autoload_register('CoreOverrideAutoloader::loader', true, true);
directly before:
require_once JPATH_BASE . '/includes/framework.php';
(both index.php files have that line)
Create /libraries/core-overrides/coreOverrideAutoloader.php:
<?php
class CoreOverrideAutoloader
{
public static $requested = array();
public static $filesLoaded = array();
public static $filesNotLoaded = array();
public static function loader($class)
{
CoreOverrideAutoloader::$requested[] = $class;
$filename = __DIR__ . '/' . strtolower($class) . '.php';
$file=$filename;
if (!file_exists($file))
{
CoreOverrideAutoloader::$filesNotLoaded[] = $file;
return false;
}
include $file;
CoreOverrideAutoloader::$filesLoaded[] = $file;
}
}
Then create /libraries/core-overrides/jform.php
That'll hold your modified JForm class:
<?php
defined('JPATH_PLATFORM') or die;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
jimport('joomla.filesystem.path');
class JForm
{
...
}
Creating any other library overrides is as simple as creating additional jclassname.php files in that same folder.
WARNING
Regardless of which solution works for you remember that both create a maintenance issue. With the core hack solution Joomla updates may undo the core hack so you'll need to check your index.php files after every Joomla update (yuck). Secondly, with either solution there is the possibility that the original JForm may be updated with a Joomla update. That wont affect your modified version but you still need to check for what was changed in the core JForm and possibly update your modified version with those same changes. Last thing you want is site errors or security vulnerabilities because your slightly modified version of JForm is multiple version behind the core JForm.