Actions

API16

Difference between revisions of "JForm/bind"

From Joomla! Documentation

< API16:JForm
(New page: ===Description=== Method to recursively bind values to form fields. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowi...)
 
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/bind|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JForm/bind}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 106: Line 106:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JForm/bind|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JForm/bind}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 121: Line 121:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 21:52, 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

Method to recursively bind values to form fields.

[<! removed edit link to red link >]

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

Syntax

bind($data, $limit=null)
Parameter Name Default Value Description
$data $data An array or object of form values.
$limit null $group The group to bind the fields to.

Returns

boolean True on success, false otherwise.

Defined in

libraries/joomla/form/form.php

Importing

jimport( 'joomla.form.form' );

Source Body

public function bind($data, $limit = null)
{
        // The data must be an object or array.
        if (!is_object($data) && !is_array($data)) {
                return false;
        }
 
        // Convert objects to arrays.
        if (is_object($data)) {
                // Handle a JRegistry/JParameter object.
                if ($data instanceof JRegistry) {
                        $data = $data->toArray();
                }
                // Handle a JObject.
                elseif ($data instanceof JObject) {
                        $data = $data->getProperties();
                }
                // Handle other types of objects.
                else {
                        $data = (array)$data;
                }
        }
 
        // Iterate through the groups.
        foreach ($this->_groups as $group => $fields) {
                $array = $this->_fieldsets[$group]['array'];
                if ($array === true) {
                        if(isset($this->_fieldsets[$group]['parent'])) {
                                $groupControl = $this->_fieldsets[$group]['parent'];
                        } else {
                                $groupControl = $group;
                        }
                } else {
                        $groupControl = $array;
                }
                // Bind if no group is specified or if the group matches the current group.
                if ($limit === null || ($limit !== null && $group === $limit)) {
                        // Iterate through the values.
                        foreach ($data as $k => $v) {
                                // If the field name matches the name of the group and the value is not scalar, recurse.
                                if ($k == $groupControl && !is_scalar($v) && !is_resource($v)) {
                                        if(isset($this->_fieldsets[$group]['children']))
                                        {
                                                $childgroups = $this->_fieldsets[$group]['children'];
                                                array_unshift($childgroups, $group);
                                                foreach($childgroups as $cgroup)
                                                {
                                                        $this->bind($v, $cgroup);
                                                }
                                        } else {
                                                $this->bind($v, $group);
                                        }
                                } else {
                                        // Bind the value to the field if it exists.
                                        if (isset($this->_groups[$group][$k]) && is_object($this->_groups[$group][$k])) {
                                                $this->_data[$group][$k] = $v;
                                        }
                                        if (isset($this->_fieldsets[$group]['parent']) && isset($this->_groups[$this->_fieldsets[$group]['parent']][$k]) && is_object($this->_groups[$this->_fieldsets[$group]['parent']][$k])) {
                                                $this->_data[$group][$k] = $v;
                                        }
                                }
                        }
                }
        }
 
        return true;
}

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

Examples

<CodeExamplesForm />