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]]

Revision as of 21:52, 13 May 2013

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.

Description[edit]

Method to recursively bind values to form fields.

[<! removed edit link to red link >]

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

Syntax[edit]

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[edit]

boolean True on success, false otherwise.

Defined in[edit]

libraries/joomla/form/form.php

Importing[edit]

jimport( 'joomla.form.form' );

Source Body[edit]

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[edit]

<CodeExamplesForm />