Zend_Form_Element handles a variety of attributes and
element metadata. Basic attributes include:
name: the element name. Uses the
setName()andgetName()accessors.label: the element label. Uses the
setLabel()andgetLabel()accessors.order: the index at which an element should appear in the form. Uses the
setOrder()andgetOrder()accessors.value: the current element value. Uses the
setValue()andgetValue()accessors.description: a description of the element; often used to provide tooltip or javascript contextual hinting describing the purpose of the element. Uses the
setDescription()andgetDescription()accessors.required: flag indicating whether or not the element is required when performing form validation. Uses the
setRequired()andgetRequired()accessors. This flag isFALSEby default.allowEmpty: flag indicating whether or not a non-required (optional) element should attempt to validate empty values. If it is set to
TRUEand the required flag isFALSE, empty values are not passed to the validator chain and are presumedTRUE. Uses thesetAllowEmpty()andgetAllowEmpty()accessors. This flag isTRUEby default.autoInsertNotEmptyValidator: flag indicating whether or not to insert a 'NotEmpty' validator when the element is required. By default, this flag is
TRUE. Set the flag withsetAutoInsertNotEmptyValidator($flag)and determine the value withautoInsertNotEmptyValidator().
Form elements may require additional metadata. For XHTML form elements, for instance, you may want to specify attributes such as the class or id. To facilitate this are a set of accessors:
setAttrib($name, $value): add an attribute
setAttribs(array $attribs): like addAttribs(), but overwrites
getAttrib($name): retrieve a single attribute value
getAttribs(): retrieve all attributes as key/value pairs
Most of the time, however, you can simply access them as object
properties, as Zend_Form_Element utilizes overloading
to facilitate access to them:
<?php
// Equivalent to $element->setAttrib('class', 'text'):
$element->class = 'text;
By default, all attributes are passed to the view helper used by the element during rendering, and rendered as HTML attributes of the element tag.




