Actions

API16

Difference between revisions of "JForm/loadFieldsXML"

From Joomla! Documentation

< API16:JForm
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JForm/loadFieldsXML|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JForm/loadFieldsXML}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 138: Line 138:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JForm/loadFieldsXML|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JForm/loadFieldsXML}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 153: Line 153:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:53, 13 May 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Loads form fields from an XML fields element optionally reseting fields before loading new ones.

[<! removed edit link to red link >]

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

Syntax

loadFieldsXML(&$xml, $reset=true, $parent=null)
Parameter Name Default Value Description
&$xml $xml The XML fields object.
$reset true $reset Flag to toggle whether the form groups should be reset.
$parent null

Returns

boolean True on success, false otherwise.

Defined in

libraries/joomla/form/form.php

Importing

jimport( 'joomla.form.form' );

Source Body

public function loadFieldsXML(&$xml, $reset = true, $parent = null)
{
        // Check for an XML object.
        if (!is_object($xml)) {
                return false;
        }
 
        // Get the group name.
        $group = ((string)$xml->attributes()->group) ? (string)$xml->attributes()->group : '_default';
 
        // Initialise the data group.
        if ($reset) {
                $this->_data[$group] = array();
        } else {
                if (!isset($this->_data[$group])) {
                        $this->_data[$group] = array();
                }
        }
 
        if(!isset($this->_fieldsets[$group]))
        {
                // Get the fieldset attributes.
                $this->_fieldsets[$group] = array();
        }
 
        if($parent && $value = (string) $xml->attributes()->group) {
                $this->_fieldsets[$parent]['children'][] = $value;
                $this->_fieldsets[$group]['parent'] = $parent;
        }
 
        // Get the fieldset label.
        if ($value = (string)$xml->attributes()->label) {
                $this->_fieldsets[$group]['label'] = $value;
        }
 
        // Get the fieldset description.
        if ($value = (string)$xml->attributes()->description) {
                $this->_fieldsets[$group]['description'] = $value;
        }
 
        // Get an optional hidden setting (at the discretion of the renderer to honour).
        if ($value = (string)$xml->attributes()->hidden) {
                $this->_fieldsets[$group]['hidden'] = ($value == 'true' || $value == 1) ? true : false;
        }
 
        // Get the fieldset array option.
        $array = (string)$xml->attributes()->array;
        if ($array=='true') {
                $this->_fieldsets[$group]['array'] = true;
        } elseif($array=='false' || empty($array)) {
                $this->_fieldsets[$group]['array'] = false;
        } else {
                $this->_fieldsets[$group]['array'] = $array;
        }
 
        // Check if there is a field path to handle.
        if ((string)$xml->attributes()->addfieldpath) {
                jimport('joomla.filesystem.folder');
                jimport('joomla.filesystem.path');
                $path = JPath::clean(JPATH_ROOT.DS.$xml->attributes()->addfieldpath);
 
                // Add the field path to the list if it exists.
                if (JFolder::exists($path)) {
                        self::addFieldPath($path);
                }
        }
 
        if ($reset) {
                // Reset the field group.
                $this->_groups[$group] = array();
 
                if($xml->fields)
                {
                        $this->loadFieldsXML($xml->fields, $reset, $group);
                }
 
                // Add the fields to the group.
                foreach ($xml->field as $field) {
                        $this->_groups[$group][(string)$field->attributes()->name] = $field;
                }
        } else {
                if($xml->fields)
                {
                        $this->loadFieldsXML($xml->fields, $reset, $group);
                }
 
                // Add to the field group.
                foreach ($xml->field as $field) {
                        $this->_groups[$group][(string)$field->attributes()->name] = $field;
                }
        }
 
 
        return true;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />