Zend Framework  1.12
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Form_Element Class Reference

Public Member Functions

 __construct ($spec, $options=null)
 Constructor.
 
 init ()
 Initialize object; used by extending classes.
 
 setDisableLoadDefaultDecorators ($flag)
 Set flag to disable loading default decorators.
 
 loadDefaultDecoratorsIsDisabled ()
 Should we load the default decorators?
 
 loadDefaultDecorators ()
 Load default decorators.
 
 setOptions (array $options)
 Set object state from options array.
 
 setConfig (Zend_Config $config)
 Set object state from Zend_Config object.
 
 setTranslator ($translator=null)
 Set translator object for localization.
 
 getTranslator ()
 Retrieve localization translator object.
 
 hasTranslator ()
 Does this element have its own specific translator?
 
 setDisableTranslator ($flag)
 Indicate whether or not translation should be disabled.
 
 translatorIsDisabled ()
 Is translation disabled?
 
 filterName ($value, $allowBrackets=false)
 Filter a name to only allow valid variable characters.
 
 setName ($name)
 Set element name.
 
 getName ()
 Return element name.
 
 getFullyQualifiedName ()
 Get fully qualified name.
 
 getId ()
 Get element id.
 
 setValue ($value)
 Set element value.
 
 getValue ()
 Retrieve filtered element value.
 
 getUnfilteredValue ()
 Retrieve unfiltered element value.
 
 setLabel ($label)
 Set element label.
 
 getLabel ()
 Retrieve element label.
 
 setOrder ($order)
 Set element order.
 
 getOrder ()
 Retrieve element order.
 
 setRequired ($flag=true)
 Set required flag.
 
 isRequired ()
 Is the element required?
 
 setAutoInsertNotEmptyValidator ($flag)
 Set flag indicating whether a NotEmpty validator should be inserted when element is required.
 
 autoInsertNotEmptyValidator ()
 Get flag indicating whether a NotEmpty validator should be inserted when element is required.
 
 setDescription ($description)
 Set element description.
 
 getDescription ()
 Retrieve element description.
 
 setAllowEmpty ($flag)
 Set 'allow empty' flag.
 
 getAllowEmpty ()
 Get 'allow empty' flag.
 
 setIgnore ($flag)
 Set ignore flag (used when retrieving values at form level)
 
 getIgnore ()
 Get ignore flag (used when retrieving values at form level)
 
 setIsArray ($flag)
 Set flag indicating if element represents an array.
 
 isArray ()
 Is the element representing an array?
 
 setBelongsTo ($array)
 Set array to which element belongs.
 
 getBelongsTo ()
 Return array name to which element belongs.
 
 getType ()
 Return element type.
 
 setAttrib ($name, $value)
 Set element attribute.
 
 setAttribs (array $attribs)
 Set multiple attributes at once.
 
 getAttrib ($name)
 Retrieve element attribute.
 
 getAttribs ()
 Return all attributes.
 
 setConcatJustValuesInErrorMessage ($concatJustValuesInErrorMessage)
 Use one error message for array elements with concatenated values.
 
 getConcatJustValuesInErrorMessage ()
 Use one error message for array elements with concatenated values.
 
 __get ($key)
 Overloading: retrieve object property.
 
 __set ($key, $value)
 Overloading: set object property.
 
 __call ($method, $args)
 Overloading: allow rendering specific decorators.
 
 setPluginLoader (Zend_Loader_PluginLoader_Interface $loader, $type)
 Set plugin loader to use for validator or filter chain.
 
 getPluginLoader ($type)
 Retrieve plugin loader for validator or filter chain.
 
 addPrefixPath ($prefix, $path, $type=null)
 Add prefix path for plugin loader.
 
 addPrefixPaths (array $spec)
 Add many prefix paths at once.
 
 addValidator ($validator, $breakChainOnFailure=false, $options=array())
 Add validator to validation chain.
 
 addValidators (array $validators)
 Add multiple validators.
 
 setValidators (array $validators)
 Set multiple validators, overwriting previous validators.
 
 getValidator ($name)
 Retrieve a single validator by name.
 
 getValidators ()
 Retrieve all validators.
 
 removeValidator ($name)
 Remove a single validator by name.
 
 clearValidators ()
 Clear all validators.
 
 isValid ($value, $context=null)
 Validate element value.
 
 addErrorMessage ($message)
 Add a custom error message to return in the event of failed validation.
 
 addErrorMessages (array $messages)
 Add multiple custom error messages to return in the event of failed validation.
 
 setErrorMessages (array $messages)
 Same as addErrorMessages(), but clears custom error message stack first.
 
 getErrorMessages ()
 Retrieve custom error messages.
 
 clearErrorMessages ()
 Clear custom error messages stack.
 
 getErrorMessageSeparator ()
 Get errorMessageSeparator.
 
 setErrorMessageSeparator ($separator)
 Set errorMessageSeparator.
 
 markAsError ()
 Mark the element as being in a failed validation state.
 
 addError ($message)
 Add an error message and mark element as failed validation.
 
 addErrors (array $messages)
 Add multiple error messages and flag element as failed validation.
 
 setErrors (array $messages)
 Overwrite any previously set error messages and flag as failed validation.
 
 hasErrors ()
 Are there errors registered?
 
 getErrors ()
 Retrieve validator chain errors.
 
 getMessages ()
 Retrieve error messages.
 
 addFilter ($filter, $options=array())
 Add a filter to the element.
 
 addFilters (array $filters)
 Add filters to element.
 
 setFilters (array $filters)
 Add filters to element, overwriting any already existing.
 
 getFilter ($name)
 Retrieve a single filter by name.
 
 getFilters ()
 Get all filters.
 
 removeFilter ($name)
 Remove a filter by name.
 
 clearFilters ()
 Clear all filters.
 
 setView (Zend_View_Interface $view=null)
 Set view object.
 
 getView ()
 Retrieve view object.
 
 addDecorator ($decorator, $options=null)
 Add a decorator for rendering the element.
 
 addDecorators (array $decorators)
 Add many decorators at once.
 
 setDecorators (array $decorators)
 Overwrite all decorators.
 
 getDecorator ($name)
 Retrieve a registered decorator.
 
 getDecorators ()
 Retrieve all decorators.
 
 removeDecorator ($name)
 Remove a single decorator.
 
 clearDecorators ()
 Clear all decorators.
 
 render (Zend_View_Interface $view=null)
 Render form element.
 
 __toString ()
 String representation of form element.
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 Returns true if and only if $value meets the validation requirements.
 

Static Public Member Functions

static resolveElementId (Zend_Form_Decorator_Interface $decorator)
 Used to resolve and return an element ID.
 

Public Attributes

const DECORATOR = 'DECORATOR'
 Element Constants.
 
const FILTER = 'FILTER'
 
const VALIDATE = 'VALIDATE'
 
 $helper = 'formText'
 

Protected Member Functions

 _filterValue (&$value, &$key)
 Filter a value.
 
 _getDecorator ($name, $options)
 Instantiate a decorator based on class name or class name fragment.
 
 _loadFilter (array $filter)
 Lazy-load a filter.
 
 _loadValidator (array $validator)
 Lazy-load a validator.
 
 _loadDecorator (array $decorator, $name)
 Lazy-load a decorator.
 
 _getErrorMessages ()
 Retrieve error messages and perform translation and value substitution.
 
 _hasErrorMessages ()
 Are there custom error messages registered?
 

Protected Attributes

 $_allowEmpty = true
 
 $_autoInsertNotEmptyValidator = true
 
 $_belongsTo
 
 $_decorators = array()
 
 $_description
 
 $_disableLoadDefaultDecorators = false
 
 $_errorMessages = array()
 
 $_errors = array()
 
 $_errorMessageSeparator = '; '
 
 $_filters = array()
 
 $_ignore = false
 
 $_isArray = false
 
 $_isError = false
 
 $_isErrorForced = false
 
 $_label
 
 $_loaders = array()
 
 $_messages = array()
 
 $_name
 
 $_order
 
 $_required = false
 
 $_translator
 
 $_translatorDisabled = false
 
 $_type
 
 $_validators = array()
 
 $_validatorRules = array()
 
 $_value
 
 $_view
 
 $_isPartialRendering = false
 
 $_concatJustValuesInErrorMessage = false
 

Constructor & Destructor Documentation

__construct (   $spec,
  $options = null 
)

Constructor.

$spec may be:

  • string: name of element
  • array: options with which to configure element
  • Zend_Config: Zend_Config with options for configuring element
Parameters
string | array | Zend_Config$spec
array | Zend_Config$options
Returns
void
Exceptions
Zend_Form_Exceptionif no element name after initialization

Extensions

Register ViewHelper decorator by default

Member Function Documentation

__call (   $method,
  $args 
)

Overloading: allow rendering specific decorators.

Call renderDecoratorName() to render a specific decorator.

Parameters
string$method
array$args
Returns
string
Exceptions
Zend_Form_Exceptionfor invalid decorator or invalid method call
__get (   $key)

Overloading: retrieve object property.

Prevents access to properties beginning with '_'.

Parameters
string$key
Returns
mixed
__set (   $key,
  $value 
)

Overloading: set object property.

Parameters
string$key
mixed$value
Returns
voide
__toString ( )

String representation of form element.

Proxies to render().

Returns
string
_filterValue ( $value,
$key 
)
protected

Filter a value.

Parameters
string$value
string$key
Returns
void
_getDecorator (   $name,
  $options 
)
protected

Instantiate a decorator based on class name or class name fragment.

Parameters
string$name
null | array$options
Returns
Zend_Form_Decorator_Interface
_getErrorMessages ( )
protected

Retrieve error messages and perform translation and value substitution.

Returns
array
_hasErrorMessages ( )
protected

Are there custom error messages registered?

Returns
bool
_loadDecorator ( array  $decorator,
  $name 
)
protected

Lazy-load a decorator.

Parameters
array$decoratorDecorator type and options
mixed$nameDecorator name or alias
Returns
Zend_Form_Decorator_Interface
_loadFilter ( array  $filter)
protected

Lazy-load a filter.

Parameters
array$filter
Returns
Zend_Filter_Interface
_loadValidator ( array  $validator)
protected

Lazy-load a validator.

Parameters
array$validatorValidator definition
Returns
Zend_Validate_Interface
addDecorator (   $decorator,
  $options = null 
)

Add a decorator for rendering the element.

Parameters
string | Zend_Form_Decorator_Interface$decorator
array | Zend_Config$optionsOptions with which to initialize decorator
Returns
Zend_Form_Element
addDecorators ( array  $decorators)

Add many decorators at once.

Parameters
array$decorators
Returns
Zend_Form_Element
addError (   $message)

Add an error message and mark element as failed validation.

Parameters
string$message
Returns
Zend_Form_Element
addErrorMessage (   $message)

Add a custom error message to return in the event of failed validation.

Parameters
string$message
Returns
Zend_Form_Element
addErrorMessages ( array  $messages)

Add multiple custom error messages to return in the event of failed validation.

Parameters
array$messages
Returns
Zend_Form_Element
addErrors ( array  $messages)

Add multiple error messages and flag element as failed validation.

Parameters
array$messages
Returns
Zend_Form_Element
addFilter (   $filter,
  $options = array() 
)

Add a filter to the element.

Parameters
string | Zend_Filter_Interface$filter
Returns
Zend_Form_Element
addFilters ( array  $filters)

Add filters to element.

Parameters
array$filters
Returns
Zend_Form_Element
addPrefixPath (   $prefix,
  $path,
  $type = null 
)

Add prefix path for plugin loader.

If no $type specified, assumes it is a base path for both filters and validators, and sets each according to the following rules:

  • decorators: $prefix = $prefix . '_Decorator'
  • filters: $prefix = $prefix . '_Filter'
  • validators: $prefix = $prefix . '_Validate'

Otherwise, the path prefix is set on the appropriate plugin loader.

Parameters
string$prefix
string$path
string$type
Returns
Zend_Form_Element
Exceptions
Zend_Form_Exceptionfor invalid type
addPrefixPaths ( array  $spec)

Add many prefix paths at once.

Parameters
array$spec
Returns
Zend_Form_Element
addValidator (   $validator,
  $breakChainOnFailure = false,
  $options = array() 
)

Add validator to validation chain.

Note: will overwrite existing validators if they are of the same class.

Parameters
string | Zend_Validate_Interface$validator
bool$breakChainOnFailure
array$options
Returns
Zend_Form_Element
Exceptions
Zend_Form_Exceptionif invalid validator type
addValidators ( array  $validators)

Add multiple validators.

Parameters
array$validators
Returns
Zend_Form_Element
autoInsertNotEmptyValidator ( )

Get flag indicating whether a NotEmpty validator should be inserted when element is required.

Returns
bool
clearDecorators ( )

Clear all decorators.

Returns
Zend_Form_Element
clearErrorMessages ( )

Clear custom error messages stack.

Returns
Zend_Form_Element
clearFilters ( )

Clear all filters.

Returns
Zend_Form_Element
clearValidators ( )

Clear all validators.

Returns
Zend_Form_Element
filterName (   $value,
  $allowBrackets = false 
)

Filter a name to only allow valid variable characters.

Parameters
string$value
bool$allowBrackets
Returns
string
getAllowEmpty ( )

Get 'allow empty' flag.

Returns
bool
getAttrib (   $name)

Retrieve element attribute.

Parameters
string$name
Returns
string
getAttribs ( )

Return all attributes.

Returns
array
getBelongsTo ( )

Return array name to which element belongs.

Returns
string
getConcatJustValuesInErrorMessage ( )

Use one error message for array elements with concatenated values.

Returns
boolean
getDecorator (   $name)

Retrieve a registered decorator.

Parameters
string$name
Returns
false|Zend_Form_Decorator_Abstract
getDecorators ( )

Retrieve all decorators.

Returns
array
getDescription ( )

Retrieve element description.

Returns
string
getErrorMessages ( )

Retrieve custom error messages.

Returns
array
getErrorMessageSeparator ( )

Get errorMessageSeparator.

Returns
string
getErrors ( )

Retrieve validator chain errors.

Returns
array
getFilter (   $name)

Retrieve a single filter by name.

Parameters
string$name
Returns
Zend_Filter_Interface
getFilters ( )

Get all filters.

Returns
array
getFullyQualifiedName ( )

Get fully qualified name.

Places name as subitem of array and/or appends brackets.

Returns
string
getId ( )

Get element id.

Returns
string
getIgnore ( )

Get ignore flag (used when retrieving values at form level)

Returns
bool
getLabel ( )

Retrieve element label.

Returns
string
getMessages ( )

Retrieve error messages.

Returns
array

Implements Zend_Validate_Interface.

getName ( )

Return element name.

Returns
string
getOrder ( )

Retrieve element order.

Returns
int
getPluginLoader (   $type)

Retrieve plugin loader for validator or filter chain.

Instantiates with default rules if none available for that type. Use 'decorator', 'filter', or 'validate' for $type.

Parameters
string$type
Returns
Zend_Loader_PluginLoader
Exceptions
Zend_Loader_Exceptionon invalid type.
getTranslator ( )

Retrieve localization translator object.

Returns
Zend_Translate_Adapter|null
getType ( )

Return element type.

Returns
string
getUnfilteredValue ( )

Retrieve unfiltered element value.

Returns
mixed
getValidator (   $name)

Retrieve a single validator by name.

Parameters
string$name
Returns
Zend_Validate_Interface|false False if not found, validator otherwise
getValidators ( )

Retrieve all validators.

Returns
array
getValue ( )

Retrieve filtered element value.

Returns
mixed
getView ( )

Retrieve view object.

Retrieves from ViewRenderer if none previously set.

Returns
null|Zend_View_Interface
hasErrors ( )

Are there errors registered?

Returns
bool
hasTranslator ( )

Does this element have its own specific translator?

Returns
bool
init ( )

Initialize object; used by extending classes.

Returns
void
isArray ( )

Is the element representing an array?

Returns
bool
isRequired ( )

Is the element required?

Returns
bool
isValid (   $value,
  $context = null 
)

Validate element value.

If a translation adapter is registered, any error messages will be translated according to the current locale, using the given error code; if no matching translation is found, the original message will be utilized.

Note: The *filtered* value is validated.

Parameters
mixed$value
mixed$context
Returns
boolean
loadDefaultDecorators ( )

Load default decorators.

Returns
Zend_Form_Element
loadDefaultDecoratorsIsDisabled ( )

Should we load the default decorators?

Returns
bool
markAsError ( )

Mark the element as being in a failed validation state.

Returns
Zend_Form_Element
removeDecorator (   $name)

Remove a single decorator.

Parameters
string$name
Returns
Zend_Form_Element
removeFilter (   $name)

Remove a filter by name.

Parameters
string$name
Returns
Zend_Form_Element
removeValidator (   $name)

Remove a single validator by name.

Parameters
string$name
Returns
bool
render ( Zend_View_Interface  $view = null)

Render form element.

Parameters
Zend_View_Interface$view
Returns
string
static resolveElementId ( Zend_Form_Decorator_Interface  $decorator)
static

Used to resolve and return an element ID.

Passed to the HtmlTag decorator as a callback in order to provide an ID.

Parameters
Zend_Form_Decorator_Interface$decorator
Returns
string
setAllowEmpty (   $flag)

Set 'allow empty' flag.

When the allow empty flag is enabled and the required flag is false, the element will validate with empty values.

Parameters
bool$flag
Returns
Zend_Form_Element
setAttrib (   $name,
  $value 
)

Set element attribute.

Parameters
string$name
mixed$value
Returns
Zend_Form_Element
Exceptions
Zend_Form_Exceptionfor invalid $name values
setAttribs ( array  $attribs)

Set multiple attributes at once.

Parameters
array$attribs
Returns
Zend_Form_Element
setAutoInsertNotEmptyValidator (   $flag)

Set flag indicating whether a NotEmpty validator should be inserted when element is required.

Parameters
bool$flag
Returns
Zend_Form_Element
setBelongsTo (   $array)

Set array to which element belongs.

Parameters
string$array
Returns
Zend_Form_Element
setConcatJustValuesInErrorMessage (   $concatJustValuesInErrorMessage)

Use one error message for array elements with concatenated values.

Parameters
boolean$concatJustValuesInErrorMessage
Returns
Zend_Form_Element
setConfig ( Zend_Config  $config)

Set object state from Zend_Config object.

Parameters
Zend_Config$config
Returns
Zend_Form_Element
setDecorators ( array  $decorators)

Overwrite all decorators.

Parameters
array$decorators
Returns
Zend_Form_Element
setDescription (   $description)

Set element description.

Parameters
string$description
Returns
Zend_Form_Element
setDisableLoadDefaultDecorators (   $flag)

Set flag to disable loading default decorators.

Parameters
bool$flag
Returns
Zend_Form_Element
setDisableTranslator (   $flag)

Indicate whether or not translation should be disabled.

Parameters
bool$flag
Returns
Zend_Form_Element
setErrorMessages ( array  $messages)

Same as addErrorMessages(), but clears custom error message stack first.

Parameters
array$messages
Returns
Zend_Form_Element
setErrorMessageSeparator (   $separator)

Set errorMessageSeparator.

Parameters
string$separator
Returns
Zend_Form_Element
setErrors ( array  $messages)

Overwrite any previously set error messages and flag as failed validation.

Parameters
array$messages
Returns
Zend_Form_Element
setFilters ( array  $filters)

Add filters to element, overwriting any already existing.

Parameters
array$filters
Returns
Zend_Form_Element
setIgnore (   $flag)

Set ignore flag (used when retrieving values at form level)

Parameters
bool$flag
Returns
Zend_Form_Element
setIsArray (   $flag)

Set flag indicating if element represents an array.

Parameters
bool$flag
Returns
Zend_Form_Element
setLabel (   $label)

Set element label.

Parameters
string$label
Returns
Zend_Form_Element
setName (   $name)

Set element name.

Parameters
string$name
Returns
Zend_Form_Element
setOptions ( array  $options)

Set object state from options array.

Parameters
array$options
Returns
Zend_Form_Element
setOrder (   $order)

Set element order.

Parameters
int$order
Returns
Zend_Form_Element
setPluginLoader ( Zend_Loader_PluginLoader_Interface  $loader,
  $type 
)

Set plugin loader to use for validator or filter chain.

Parameters
Zend_Loader_PluginLoader_Interface$loader
string$type'decorator', 'filter', or 'validate'
Returns
Zend_Form_Element
Exceptions
Zend_Form_Exceptionon invalid type
setRequired (   $flag = true)

Set required flag.

Parameters
bool$flagDefault value is true
Returns
Zend_Form_Element
setTranslator (   $translator = null)

Set translator object for localization.

Parameters
Zend_Translate | null$translator
Returns
Zend_Form_Element
setValidators ( array  $validators)

Set multiple validators, overwriting previous validators.

Parameters
array$validators
Returns
Zend_Form_Element
setValue (   $value)

Set element value.

Parameters
mixed$value
Returns
Zend_Form_Element
setView ( Zend_View_Interface  $view = null)

Set view object.

Parameters
Zend_View_Interface$view
Returns
Zend_Form_Element
translatorIsDisabled ( )

Is translation disabled?

Returns
bool

Member Data Documentation

$_allowEmpty = true
protected
$_autoInsertNotEmptyValidator = true
protected
$_belongsTo
protected
$_concatJustValuesInErrorMessage = false
protected
$_decorators = array()
protected
$_description
protected
$_disableLoadDefaultDecorators = false
protected
$_errorMessages = array()
protected
$_errorMessageSeparator = '; '
protected
$_errors = array()
protected
$_filters = array()
protected
$_ignore = false
protected
$_isArray = false
protected
$_isError = false
protected
$_isErrorForced = false
protected
$_isPartialRendering = false
protected
$_label
protected
$_loaders = array()
protected
$_messages = array()
protected
$_name
protected
$_order
protected
$_required = false
protected
$_translator
protected
$_translatorDisabled = false
protected
$_type
protected
$_validatorRules = array()
protected
$_validators = array()
protected
$_value
protected
$_view
protected
$helper = 'formText'
const DECORATOR = 'DECORATOR'

Element Constants.

const FILTER = 'FILTER'
const VALIDATE = 'VALIDATE'