From Joomla! Documentation

< API16:JForm

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Method to load a form field object.

<! removed transcluded page call, red link never existed >


loadFieldType($type, $new=true)
Parameter Name Default Value Description
$type $type The field type.
$new true $new Flag to toggle whether we should get a new instance of the object.


mixed Field object on success, false otherwise.

Defined in



jimport( 'joomla.form.form' );

Source Body

public function loadFieldType($type, $new = true)
        $key    = md5($type);
        $class  = 'JFormField'.ucfirst($type);

        // Return the field object if it already exists and we don't need a new one.
        if (isset($this->_fieldTypes[$key]) && $new === false) {
                return $this->_fieldTypes[$key];

        if (!class_exists('JFormField')) {

        if (!class_exists('JFormFieldList')) {
                require_once dirname(__FILE__).'/fields/list.php';

        if (!class_exists($class)) {
                $paths = self::addFieldPath();

                // If the type is complex, add the base type to the paths.
                if ($pos = strpos($type, '_')) {
                        // Add the complex type prefix to the paths.
                        for ($i = 0, $n = count($paths); $i < $n; $i++) {
                                // Derive the new path.
                                $path = $paths[$i].DS.strtolower(substr($type, 0, $pos));

                                // If the path does not exist, add it.
                                if (!in_array($path, $paths)) {
                                        array_unshift($paths, $path);

                        // Break off the end of the complex type.
                        $type = substr($type, $pos+1);

                // Try to find the field file.
                if ($file = JPath::find($paths, strtolower($type).'.php')) {
                        require_once $file;
                } else {
                        return false;

                // Check once and for all if the class exists.
                if (!class_exists($class)) {
                        return false;

        // Instantiate a new field object.
        $this->_fieldTypes[$key] = new $class($this);

        return $this->_fieldTypes[$key];

<! removed transcluded page call, red link never existed >


Code Examples