Actions

API16

Difference between revisions of "JForm/getFieldset"

From Joomla! Documentation

< API16:JForm
(Defined in)
(Importing)
Line 6: Line 6:
 
===Importing===
 
===Importing===
 
<source lang="php">jimport( 'joomla.form.form' );</source>
 
<source lang="php">jimport( 'joomla.form.form' );</source>
 +
===Source Body===
 +
<source lang="php">
 +
public function getFieldset($set = null)
 +
{
 +
// Initialize variables.
 +
$fields = array();
 +
 +
// Get all of the field elements in the fieldset.
 +
if ($set) {
 +
$elements = $this->findFieldsByFieldset($set);
 +
}
 +
// Get all fields.
 +
else {
 +
$elements = $this->findFieldsByGroup();
 +
}
 +
 +
// If no field elements were found return empty.
 +
if (empty($elements)) {
 +
return $fields;
 +
}
 +
 +
// Build the result array from the found field elements.
 +
foreach ($elements as $element) {
 +
 +
// Get the field groups for the element.
 +
$attrs = $element->xpath('ancestor::fields[@name]/@name');
 +
$groups = array_map('strval', $attrs ? $attrs : array());
 +
$group = implode('.', $groups);
 +
 +
// If the field is successfully loaded add it to the result array.
 +
if ($field = $this->loadField($element, $group)) {
 +
$fields[$field->id] = $field;
 +
}
 +
}
 +
 +
return $fields;
 +
}
 +
</span>

Revision as of 04:59, 27 August 2010

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

Syntax

getFieldset()

Defined in

libraries/joomla/form/form.php

Importing

jimport( 'joomla.form.form' );

Source Body

public function getFieldset($set = null)
{
        // Initialize variables.
        $fields = array();
 
        // Get all of the field elements in the fieldset.
        if ($set) {
                $elements = $this->findFieldsByFieldset($set);
        }
        // Get all fields.
        else {
                $elements = $this->findFieldsByGroup();
        }
 
        // If no field elements were found return empty.
        if (empty($elements)) {
                return $fields;
        }
 
        // Build the result array from the found field elements.
        foreach ($elements as $element) {
 
                // Get the field groups for the element.
                $attrs  = $element->xpath('ancestor::fields[@name]/@name');
                $groups = array_map('strval', $attrs ? $attrs : array());
                $group  = implode('.', $groups);
 
                // If the field is successfully loaded add it to the result array.
                if ($field = $this->loadField($element, $group)) {
                        $fields[$field->id] = $field;
                }
        }
 
        return $fields;
}
</span>