Form/Element.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Form  

\Zend_Form_Element

Package: Zend_Form\Element
Zend_Form_Element
Implements
Children
\Zend_Dojo_Form_Element_Dijit
\Zend_Form_Element_Xhtml
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Version
$Id$  

Constants

>VConstant  DECORATOR = 'DECORATOR'
Element Constants
>VConstant  FILTER = 'FILTER'
>VConstant  VALIDATE = 'VALIDATE'

Properties

>VPropertyprotectedbool $_allowEmpty = true
'Allow empty' flag
Default valuetrueDetails
Type
bool
>VPropertyprotectedbool $_autoInsertNotEmptyValidator = true
Flag indicating whether or not to insert NotEmpty validator when element is required
Default valuetrueDetails
Type
bool
>VPropertyprotectedstring $_belongsTo
Array to which element belongs
Details
Type
string
>VPropertyprotectedbool $_concatJustValuesInErrorMessage = false
Use one error message for array elements with concatenated values
Default valuefalseDetails
Type
bool
>VPropertyprotectedarray $_decorators = array()
Element decorators
Default valuearray()Details
Type
array
>VPropertyprotectedstring $_description
Element description
Details
Type
string
>VPropertyprotectedbool $_disableLoadDefaultDecorators = false
Should we disable loading the default decorators?
Default valuefalseDetails
Type
bool
>VPropertyprotectedstring $_errorMessageSeparator = '; '
Separator to use when concatenating aggregate error messages (for elements having array values)
Default value'; 'Details
Type
string
>VPropertyprotectedarray $_errorMessages = array()
Custom error messages
Default valuearray()Details
Type
array
>VPropertyprotectedarray $_errors = array()
Validation errors
Default valuearray()Details
Type
array
>VPropertyprotectedarray $_filters = array()
Element filters
Default valuearray()Details
Type
array
>VPropertyprotectedbool $_ignore = false
Ignore flag (used when retrieving values at form level)
Default valuefalseDetails
Type
bool
>VPropertyprotectedbool $_isArray = false
Does the element represent an array?
Default valuefalseDetails
Type
bool
>VPropertyprotectedbool $_isError = false
Is the error marked as in an invalid state?
Default valuefalseDetails
Type
bool
>VPropertyprotectedbool $_isErrorForced = false
Has the element been manually marked as invalid?
Default valuefalseDetails
Type
bool
>VPropertyprotectedbool $_isPartialRendering = false
Is a specific decorator being rendered via the magic renderDecorator()?
This is to allow execution of logic inside the render() methods of child elements during the magic call while skipping the parent render() method.
Default valuefalseDetails
Type
bool
>VPropertyprotectedstring $_label
Element label
Details
Type
string
>VPropertyprotectedarray $_loaders = array()
Plugin loaders for filter and validator chains
Default valuearray()Details
Type
array
>VPropertyprotectedarray $_messages = array()
Formatted validation error messages
Default valuearray()Details
Type
array
>VPropertyprotectedstring $_name
Element name
Details
Type
string
>VPropertyprotectedint $_order
Order of element
Details
Type
int
>VPropertyprotectedbool $_required = false
Required flag
Default valuefalseDetails
Type
bool
>VPropertyprotected\Zend_Translate $_translator
Details
Type
\Zend_Translate
>VPropertyprotectedbool $_translatorDisabled = false
Is translation disabled?
Default valuefalseDetails
Type
bool
>VPropertyprotectedstring $_type
Element type
Details
Type
string
>VPropertyprotectedarray $_validatorRules = array()
Array of un-initialized validators
Default valuearray()Details
Type
array
>VPropertyprotectedarray $_validators = array()
Array of initialized validators
Default valuearray()Details
Type
array
>VPropertyprotectedmixed $_value
Element value
Details
Type
mixed
>VPropertyprotected\Zend_View_Interface $_view
>VPropertypublicstring $helper = 'formText'
Default view helper to use
Default value'formText'Details
Type
string

Methods

methodpublic__call(string $method, array $args) : string

Overloading: allow rendering specific decorators

Call renderDecoratorName() to render a specific decorator.
Parameters
NameTypeDescription
$methodstring
$argsarray
Returns
TypeDescription
string
Throws
ExceptionDescription
\Zend_Form_Exceptionfor invalid decorator or invalid method call
methodpublic__construct(string | array | \Zend_Config $spec, array | \Zend_Config $options = null) : void

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
NameTypeDescription
$specstring | array | \Zend_Config
$optionsarray | \Zend_Config
Throws
ExceptionDescription
\Zend_Form_Exceptionif no element name after initialization
methodpublic__get(string $key) : mixed

Overloading: retrieve object property

Prevents access to properties beginning with '_'.
Parameters
NameTypeDescription
$keystring
Returns
TypeDescription
mixed
methodpublic__set(string $key, mixed $value) : \voide

Overloading: set object property

Parameters
NameTypeDescription
$keystring
$valuemixed
Returns
TypeDescription
\voide
methodpublic__toString() : string

String representation of form element

Proxies to {@link render()}.
Returns
TypeDescription
string
methodprotected_filterValue(string $value, string $key) : void

Filter a value

Parameters
NameTypeDescription
$valuestring
$keystring
methodprotected_getDecorator(string $name, null | array $options) : \Zend_Form_Decorator_Interface

Instantiate a decorator based on class name or class name fragment

Parameters
NameTypeDescription
$namestring
$optionsnull | array
Returns
TypeDescription
\Zend_Form_Decorator_Interface
methodprotected_getErrorMessages() : array

Retrieve error messages and perform translation and value substitution

Returns
TypeDescription
array
methodprotected_hasErrorMessages() : bool

Are there custom error messages registered?

Returns
TypeDescription
bool
methodprotected_loadDecorator(array $decorator, mixed $name) : \Zend_Form_Decorator_Interface

Lazy-load a decorator

Parameters
NameTypeDescription
$decoratorarray

Decorator type and options

$namemixed

Decorator name or alias

Returns
TypeDescription
\Zend_Form_Decorator_Interface
methodprotected_loadFilter(array $filter) : \Zend_Filter_Interface

Lazy-load a filter

Parameters
NameTypeDescription
$filterarray
Returns
TypeDescription
\Zend_Filter_Interface
methodprotected_loadValidator(array $validator) : \Zend_Validate_Interface

Lazy-load a validator

Parameters
NameTypeDescription
$validatorarray

Validator definition

Returns
TypeDescription
\Zend_Validate_Interface
methodpublicaddDecorator(string | \Zend_Form_Decorator_Interface $decorator, array | \Zend_Config $options = null) : \Zend_Form_Element

Add a decorator for rendering the element

Parameters
NameTypeDescription
$decoratorstring | \Zend_Form_Decorator_Interface
$optionsarray | \Zend_Config

Options with which to initialize decorator

Returns
TypeDescription
\Zend_Form_Element
methodpublicaddDecorators(array $decorators) : \Zend_Form_Element

Add many decorators at once

Parameters
NameTypeDescription
$decoratorsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddError(string $message) : \Zend_Form_Element

Add an error message and mark element as failed validation

Parameters
NameTypeDescription
$messagestring
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddErrorMessage(string $message) : \Zend_Form_Element

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

Parameters
NameTypeDescription
$messagestring
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddErrorMessages(array $messages) : \Zend_Form_Element

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

Parameters
NameTypeDescription
$messagesarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddErrors(array $messages) : \Zend_Form_Element

Add multiple error messages and flag element as failed validation

Parameters
NameTypeDescription
$messagesarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddFilter(string | \Zend_Filter_Interface $filter,  $options = array()) : \Zend_Form_Element

Add a filter to the element

Parameters
NameTypeDescription
$filterstring | \Zend_Filter_Interface
$options
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddFilters(array $filters) : \Zend_Form_Element

Add filters to element

Parameters
NameTypeDescription
$filtersarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddPrefixPath(string $prefix, string $path, string $type = null) : \Zend_Form_Element

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
NameTypeDescription
$prefixstring
$pathstring
$typestring
Returns
TypeDescription
\Zend_Form_Element
Throws
ExceptionDescription
\Zend_Form_Exceptionfor invalid type
methodpublicaddPrefixPaths(array $spec) : \Zend_Form_Element

Add many prefix paths at once

Parameters
NameTypeDescription
$specarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicaddValidator(string | \Zend_Validate_Interface $validator, bool $breakChainOnFailure = false, array $options = array()) : \Zend_Form_Element

Add validator to validation chain

Note: will overwrite existing validators if they are of the same class.
Parameters
NameTypeDescription
$validatorstring | \Zend_Validate_Interface
$breakChainOnFailurebool
$optionsarray
Returns
TypeDescription
\Zend_Form_Element
Throws
ExceptionDescription
\Zend_Form_Exceptionif invalid validator type
methodpublicaddValidators(array $validators) : \Zend_Form_Element

Add multiple validators

Parameters
NameTypeDescription
$validatorsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicautoInsertNotEmptyValidator() : bool

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

Returns
TypeDescription
bool
methodpublicclearDecorators() : \Zend_Form_Element

Clear all decorators

Returns
TypeDescription
\Zend_Form_Element
methodpublicclearErrorMessages() : \Zend_Form_Element

Clear custom error messages stack

Returns
TypeDescription
\Zend_Form_Element
methodpublicclearFilters() : \Zend_Form_Element

Clear all filters

Returns
TypeDescription
\Zend_Form_Element
methodpublicclearValidators() : \Zend_Form_Element

Clear all validators

Returns
TypeDescription
\Zend_Form_Element
methodpublicfilterName(string $value, bool $allowBrackets = false) : string

Filter a name to only allow valid variable characters

Parameters
NameTypeDescription
$valuestring
$allowBracketsbool
Returns
TypeDescription
string
methodpublicgetAllowEmpty() : bool

Get 'allow empty' flag

Returns
TypeDescription
bool
methodpublicgetAttrib(string $name) : string

Retrieve element attribute

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
string
methodpublicgetAttribs() : array

Return all attributes

Returns
TypeDescription
array
methodpublicgetBelongsTo() : string

Return array name to which element belongs

Returns
TypeDescription
string
methodpublicgetConcatJustValuesInErrorMessage() : boolean

Use one error message for array elements with concatenated values

Returns
TypeDescription
boolean
methodpublicgetDecorator(string $name) : false | \Zend_Form_Decorator_Abstract

Retrieve a registered decorator

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
false | \Zend_Form_Decorator_Abstract
methodpublicgetDecorators() : array

Retrieve all decorators

Returns
TypeDescription
array
methodpublicgetDescription() : string

Retrieve element description

Returns
TypeDescription
string
methodpublicgetErrorMessageSeparator() : string

Get errorMessageSeparator

Returns
TypeDescription
string
methodpublicgetErrorMessages() : array

Retrieve custom error messages

Returns
TypeDescription
array
methodpublicgetErrors() : array

Retrieve validator chain errors

Returns
TypeDescription
array
methodpublicgetFilter(string $name) : \Zend_Filter_Interface

Retrieve a single filter by name

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Filter_Interface
methodpublicgetFilters() : array

Get all filters

Returns
TypeDescription
array
methodpublicgetFullyQualifiedName() : string

Get fully qualified name

Places name as subitem of array and/or appends brackets.
Returns
TypeDescription
string
methodpublicgetId() : string

Get element id

Returns
TypeDescription
string
methodpublicgetIgnore() : bool

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

Returns
TypeDescription
bool
methodpublicgetLabel() : string

Retrieve element label

Returns
TypeDescription
string
methodpublicgetMessages() : array

Retrieve error messages

Returns
TypeDescription
array
methodpublicgetName() : string

Return element name

Returns
TypeDescription
string
methodpublicgetOrder() : int

Retrieve element order

Returns
TypeDescription
int
methodpublicgetPluginLoader(string $type) : \Zend_Loader_PluginLoader

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
NameTypeDescription
$typestring
Returns
TypeDescription
\Zend_Loader_PluginLoader
Throws
ExceptionDescription
\Zend_Loader_Exceptionon invalid type.
methodpublicgetTranslator() : \Zend_Translate_Adapter | null

Retrieve localization translator object

Returns
TypeDescription
\Zend_Translate_Adapter | null
methodpublicgetType() : string

Return element type

Returns
TypeDescription
string
methodpublicgetUnfilteredValue() : mixed

Retrieve unfiltered element value

Returns
TypeDescription
mixed
methodpublicgetValidator(string $name) : \Zend_Validate_Interface | false

Retrieve a single validator by name

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Validate_Interface | falseFalse if not found, validator otherwise
methodpublicgetValidators() : array

Retrieve all validators

Returns
TypeDescription
array
methodpublicgetValue() : mixed

Retrieve filtered element value

Returns
TypeDescription
mixed
methodpublicgetView() : null | \Zend_View_Interface

Retrieve view object

Retrieves from ViewRenderer if none previously set.
Returns
TypeDescription
null | \Zend_View_Interface
methodpublichasErrors() : bool

Are there errors registered?

Returns
TypeDescription
bool
methodpublichasTranslator() : bool

Does this element have its own specific translator?

Returns
TypeDescription
bool
methodpublicinit() : void

Initialize object; used by extending classes

methodpublicisArray() : bool

Is the element representing an array?

Returns
TypeDescription
bool
methodpublicisRequired() : bool

Is the element required?

Returns
TypeDescription
bool
methodpublicisValid(mixed $value, mixed $context = null) : boolean

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
NameTypeDescription
$valuemixed
$contextmixed
Returns
TypeDescription
boolean
methodpublicloadDefaultDecorators() : \Zend_Form_Element

Load default decorators

Returns
TypeDescription
\Zend_Form_Element
methodpublicloadDefaultDecoratorsIsDisabled() : bool

Should we load the default decorators?

Returns
TypeDescription
bool
methodpublicmarkAsError() : \Zend_Form_Element

Mark the element as being in a failed validation state

Returns
TypeDescription
\Zend_Form_Element
methodpublicremoveDecorator(string $name) : \Zend_Form_Element

Remove a single decorator

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Form_Element
methodpublicremoveFilter(string $name) : \Zend_Form_Element

Remove a filter by name

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Form_Element
methodpublicremoveValidator(string $name) : bool

Remove a single validator by name

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
bool
methodpublicrender(\Zend_View_Interface $view = null) : string

Render form element

Parameters
NameTypeDescription
$view\Zend_View_Interface
Returns
TypeDescription
string
methodpublicresolveElementId(\Zend_Form_Decorator_Interface $decorator) : string
static

Used to resolve and return an element ID

Passed to the HtmlTag decorator as a callback in order to provide an ID.
Parameters
NameTypeDescription
$decorator\Zend_Form_Decorator_Interface
Returns
TypeDescription
string
methodpublicsetAllowEmpty(bool $flag) : \Zend_Form_Element

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
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetAttrib(string $name, mixed $value) : \Zend_Form_Element

Set element attribute

Parameters
NameTypeDescription
$namestring
$valuemixed
Returns
TypeDescription
\Zend_Form_Element
Throws
ExceptionDescription
\Zend_Form_Exceptionfor invalid $name values
methodpublicsetAttribs(array $attribs) : \Zend_Form_Element

Set multiple attributes at once

Parameters
NameTypeDescription
$attribsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetAutoInsertNotEmptyValidator(bool $flag) : \Zend_Form_Element

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

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetBelongsTo(string $array) : \Zend_Form_Element

Set array to which element belongs

Parameters
NameTypeDescription
$arraystring
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetConcatJustValuesInErrorMessage(boolean $concatJustValuesInErrorMessage) : \Zend_Form_Element

Use one error message for array elements with concatenated values

Parameters
NameTypeDescription
$concatJustValuesInErrorMessageboolean
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetConfig(\Zend_Config $config) : \Zend_Form_Element

Set object state from Zend_Config object

Parameters
NameTypeDescription
$config\Zend_Config
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetDecorators(array $decorators) : \Zend_Form_Element

Overwrite all decorators

Parameters
NameTypeDescription
$decoratorsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetDescription(string $description) : \Zend_Form_Element

Set element description

Parameters
NameTypeDescription
$descriptionstring
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetDisableLoadDefaultDecorators(bool $flag) : \Zend_Form_Element

Set flag to disable loading default decorators

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetDisableTranslator(bool $flag) : \Zend_Form_Element

Indicate whether or not translation should be disabled

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetErrorMessageSeparator(string $separator) : \Zend_Form_Element

Set errorMessageSeparator

Parameters
NameTypeDescription
$separatorstring
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetErrorMessages(array $messages) : \Zend_Form_Element

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

Parameters
NameTypeDescription
$messagesarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetErrors(array $messages) : \Zend_Form_Element

Overwrite any previously set error messages and flag as failed validation

Parameters
NameTypeDescription
$messagesarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetFilters(array $filters) : \Zend_Form_Element

Add filters to element, overwriting any already existing

Parameters
NameTypeDescription
$filtersarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetIgnore(bool $flag) : \Zend_Form_Element

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

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetIsArray(bool $flag) : \Zend_Form_Element

Set flag indicating if element represents an array

Parameters
NameTypeDescription
$flagbool
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetLabel(string $label) : \Zend_Form_Element

Set element label

Parameters
NameTypeDescription
$labelstring
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetName(string $name) : \Zend_Form_Element

Set element name

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetOptions(array $options) : \Zend_Form_Element

Set object state from options array

Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetOrder(int $order) : \Zend_Form_Element

Set element order

Parameters
NameTypeDescription
$orderint
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetPluginLoader(\Zend_Loader_PluginLoader_Interface $loader, string $type) : \Zend_Form_Element

Set plugin loader to use for validator or filter chain

Parameters
NameTypeDescription
$loader\Zend_Loader_PluginLoader_Interface
$typestring

'decorator', 'filter', or 'validate'

Returns
TypeDescription
\Zend_Form_Element
Throws
ExceptionDescription
\Zend_Form_Exceptionon invalid type
methodpublicsetRequired(bool $flag = true) : \Zend_Form_Element

Set required flag

Parameters
NameTypeDescription
$flagbool

Default value is true

Returns
TypeDescription
\Zend_Form_Element
methodpublicsetTranslator(\Zend_Translate | null $translator = null) : \Zend_Form_Element

Set translator object for localization

Parameters
NameTypeDescription
$translator\Zend_Translate | null
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetValidators(array $validators) : \Zend_Form_Element

Set multiple validators, overwriting previous validators

Parameters
NameTypeDescription
$validatorsarray
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetValue(mixed $value) : \Zend_Form_Element

Set element value

Parameters
NameTypeDescription
$valuemixed
Returns
TypeDescription
\Zend_Form_Element
methodpublicsetView(\Zend_View_Interface $view = null) : \Zend_Form_Element

Set view object

Parameters
NameTypeDescription
$view\Zend_View_Interface
Returns
TypeDescription
\Zend_Form_Element
methodpublictranslatorIsDisabled() : bool

Is translation disabled?

Returns
TypeDescription
bool
Documentation was generated by phpDocumentor 2.2.0 .