Varien_Data_Form Class Reference

Inheritance diagram for Varien_Data_Form:

Varien_Data_Form_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ($attributes=array())
 addElement (Varien_Data_Form_Element_Abstract $element, $after=false)
 addElementToCollection ($element)
 checkElementId ($elementId)
 getForm ()
 getElement ($elementId)
 setValues ($values)
 addValues ($values)
 addFieldNameSuffix ($suffix)
 addSuffixToName ($name, $suffix)
 removeField ($elementId)
 toHtml ()
 getHtml ()

Static Public Member Functions

static setElementRenderer (Varien_Data_Form_Element_Renderer_Interface $renderer)
static setFieldsetRenderer (Varien_Data_Form_Element_Renderer_Interface $renderer)
static setFieldsetElementRenderer (Varien_Data_Form_Element_Renderer_Interface $renderer)
static getElementRenderer ()
static getFieldsetRenderer ()
static getFieldsetElementRenderer ()

Protected Member Functions

 _elementIdExists ($elementId)

Protected Attributes

 $_allElements
 $_elementsIndex

Static Protected Attributes

static $_defaultElementRenderer
static $_defaultFieldsetRenderer
static $_defaultFieldsetElementRenderer


Detailed Description

Definition at line 34 of file Form.php.


Constructor & Destructor Documentation

__construct ( attributes = array()  ) 

Enter description here...

Parameters:
array $attributes

Reimplemented from Varien_Data_Form_Abstract.

Definition at line 54 of file Form.php.

00055     {
00056         parent::__construct($attributes);
00057         $this->_allElements = new Varien_Data_Form_Element_Collection($this);
00058     }


Member Function Documentation

_elementIdExists ( elementId  )  [protected]

Check existing element

Parameters:
string $elementId
Returns:
bool

Definition at line 110 of file Form.php.

00111     {
00112         return isset($this->_elementsIndex[$elementId]);
00113     }

addElement ( Varien_Data_Form_Element_Abstract element,
after = false 
)

Add form element

Parameters:
Varien_Data_Form_Element_Abstract $element
Returns:
Varien_Data_Form

Reimplemented from Varien_Data_Form_Abstract.

Definition at line 96 of file Form.php.

00097     {
00098         $this->checkElementId($element->getId());
00099         parent::addElement($element, $after);
00100         $this->addElementToCollection($element);
00101         return $this;
00102     }

addElementToCollection ( element  ) 

Definition at line 115 of file Form.php.

00116     {
00117         $this->_elementsIndex[$element->getId()] = $element;
00118         $this->_allElements->add($element);
00119         return $this;
00120     }

addFieldNameSuffix ( suffix  ) 

Definition at line 169 of file Form.php.

00170     {
00171         foreach ($this->_allElements as $element) {
00172             $name = $element->getName();
00173             if ($name) {
00174                 $element->setName($this->addSuffixToName($name, $suffix));
00175             }
00176         }
00177     }

addSuffixToName ( name,
suffix 
)

Definition at line 179 of file Form.php.

00180     {
00181         $vars = explode('[', $name);
00182         $newName = $suffix;
00183         foreach ($vars as $index=>$value) {
00184             $newName.= '['.$value;
00185             if ($index==0) {
00186                 $newName.= ']';
00187             }
00188         }
00189         return $newName;
00190     }

addValues ( values  ) 

Definition at line 156 of file Form.php.

00157     {
00158         if (!is_array($values)) {
00159             return $this;
00160         }
00161         foreach ($values as $elementId=>$value) {
00162             if ($element = $this->getElement($elementId)) {
00163                 $element->setValue($value);
00164             }
00165         }
00166         return $this;
00167     }

checkElementId ( elementId  ) 

Definition at line 122 of file Form.php.

00123     {
00124         if ($this->_elementIdExists($elementId)) {
00125             throw new Exception('Element with id "'.$elementId.'" already exists');
00126         }
00127         return true;
00128     }

getElement ( elementId  ) 

Definition at line 135 of file Form.php.

00136     {
00137         if ($this->_elementIdExists($elementId)) {
00138             return $this->_elementsIndex[$elementId];
00139         }
00140         return null;
00141     }

static getElementRenderer (  )  [static]

Definition at line 75 of file Form.php.

00076     {
00077         return self::$_defaultElementRenderer;
00078     }

static getFieldsetElementRenderer (  )  [static]

Definition at line 85 of file Form.php.

00086     {
00087         return self::$_defaultFieldsetElementRenderer;
00088     }

static getFieldsetRenderer (  )  [static]

Definition at line 80 of file Form.php.

00081     {
00082         return self::$_defaultFieldsetRenderer;
00083     }

getForm (  ) 

Definition at line 130 of file Form.php.

00131     {
00132         return $this;
00133     }

getHtml (  ) 

Definition at line 224 of file Form.php.

00225     {
00226         return $this->toHtml();
00227     }

removeField ( elementId  ) 

Enter description here...

Parameters:
string $elementId
Returns:
Varien_Data_Form_Abstract

Reimplemented from Varien_Data_Form_Abstract.

Definition at line 192 of file Form.php.

00193     {
00194         if ($this->_elementIdExists($elementId)) {
00195             unset($this->_elementsIndex[$elementId]);
00196         }
00197         return $this;
00198     }

static setElementRenderer ( Varien_Data_Form_Element_Renderer_Interface renderer  )  [static]

Definition at line 60 of file Form.php.

00061     {
00062         self::$_defaultElementRenderer = $renderer;
00063     }

static setFieldsetElementRenderer ( Varien_Data_Form_Element_Renderer_Interface renderer  )  [static]

Definition at line 70 of file Form.php.

00071     {
00072         self::$_defaultFieldsetElementRenderer = $renderer;
00073     }

static setFieldsetRenderer ( Varien_Data_Form_Element_Renderer_Interface renderer  )  [static]

Definition at line 65 of file Form.php.

00066     {
00067         self::$_defaultFieldsetRenderer = $renderer;
00068     }

setValues ( values  ) 

Definition at line 143 of file Form.php.

00144     {
00145         foreach ($this->_allElements as $element) {
00146             if (isset($values[$element->getId()])) {
00147                 $element->setValue($values[$element->getId()]);
00148             }
00149             else {
00150                 $element->setValue(null);
00151             }
00152         }
00153         return $this;
00154     }

toHtml (  ) 

Definition at line 200 of file Form.php.

00201     {
00202         Varien_Profiler::start('form/toHtml');
00203         $html = '';
00204         if ($useContainer = $this->getUseContainer()) {
00205             $html .= '<form '.$this->serialize(array('id', 'name', 'method', 'action', 'enctype', 'class', 'onsubmit')).'>';
00206             $html .= '<div>';
00207             if (strtolower($this->getData('method')) == 'post') {
00208                 $html .= '<input name="form_key" type="hidden" value="'.Mage::getSingleton('core/session')->getFormKey().'" />';
00209             }
00210             $html .= '</div>';
00211         }
00212 
00213         foreach ($this->getElements() as $element) {
00214             $html.= $element->toHtml();
00215         }
00216 
00217         if ($useContainer) {
00218             $html.= '</form>';
00219         }
00220         Varien_Profiler::stop('form/toHtml');
00221         return $html;
00222     }


Member Data Documentation

$_allElements [protected]

Definition at line 41 of file Form.php.

$_defaultElementRenderer [static, protected]

Definition at line 50 of file Form.php.

$_defaultFieldsetElementRenderer [static, protected]

Definition at line 52 of file Form.php.

$_defaultFieldsetRenderer [static, protected]

Definition at line 51 of file Form.php.

$_elementsIndex [protected]

Definition at line 48 of file Form.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:59 2009 for Magento by  doxygen 1.5.8