Form.php
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
Package: Zend_FormZend_Form
- Implements
- Children
- \Zend_Dojo_Form
- \Zend_Form_SubForm
- Category
- Zend
- Copyright
- Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Version
- $Id$
Constants


ENCTYPE_URLENCODED
= 'application/x-www-form-urlencoded'


ENCTYPE_MULTIPART
= 'multipart/form-data'
Properties
Methods



__call(string $method, array $args) : string
Overloading: allow rendering specific decorators
Call renderDecoratorName() to render a specific decorator.
ParametersName | Type | Description |
---|
$method | string | |
---|
$args | array | |
---|
ReturnsThrows


__get(string $name) : \Zend_Form_Element | \Zend_Form | null
Overloading: access to elements, form groups, and display groups
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


__isset(string $name) : boolean
Overloading: access to elements, form groups, and display groups
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


__unset(string $name) : void
Overloading: access to elements, form groups, and display groups
ParametersName | Type | Description |
---|
$name | string | |
---|



_array_replace_recursive(array $into) : void
This is a helper function until php 5.3 is widespreaded
ParametersName | Type | Description |
---|
$into | array | |
---|
Details- Access
- protected



_attachToArray(mixed $value, string $arrayPath) : array
Converts given arrayPath to an array and attaches given value at the end of it.
ParametersName | Type | Description |
---|
$value | mixed | The value to attach |
---|
$arrayPath | string | Given array path to convert and attach to. |
---|
Returns 


_dissolveArrayUnsetKey(array $array, string | null $arrayPath, string $key) : array
Given an array, an optional arrayPath and a key this method
dissolves the arrayPath and unsets the key within the array
if it exists.
ParametersName | Type | Description |
---|
$array | array | |
---|
$arrayPath | string | null | |
---|
$key | string | |
---|
Returns 


_dissolveArrayValue(array $value, string $arrayPath) : string
Extract the value by walking the array using given array path.
Given an array path such as foo[bar][baz], returns the value of the last
element (in this case, 'baz').
ParametersName | Type | Description |
---|
$value | array | Array to walk |
---|
$arrayPath | string | Array notation path of the part to extract |
---|
Returns


_getArrayName(string $value) : string
Determine array key name from given value
Given a value such as foo[bar][baz], returns the last element (in this case, 'baz').
ParametersName | Type | Description |
---|
$value | string | |
---|
Returns


_getDecorator(string $name, null | array $options) : \Zend_Form_Decorator_Interface
Instantiate a decorator based on class name or class name fragment
ParametersName | Type | Description |
---|
$name | string | |
---|
$options | null | array | |
---|
Returns 


_loadDecorator(array $decorator, mixed $name) : \Zend_Form_Decorator_Interface
ParametersName | Type | Description |
---|
$decorator | array | Decorator type and options |
---|
$name | mixed | Decorator name or alias |
---|
Returns 


_setElementsBelongTo(string $name = null) : void
Set array to which elements belong
ParametersName | Type | Description |
---|
$name | string | Element name |
---|



addAttribs(array $attribs) : \Zend_Form
Add multiple form attributes at once
ParametersName | Type | Description |
---|
$attribs | array | |
---|
Returns 


addDecorators(array $decorators) : \Zend_Form
Add many decorators at once
ParametersName | Type | Description |
---|
$decorators | array | |
---|
Returns 


addDisplayGroupPrefixPath(string $prefix, string $path) : \Zend_Form
Add prefix path for all display groups
ParametersName | Type | Description |
---|
$prefix | string | |
---|
$path | string | |
---|
Returns 


addDisplayGroupPrefixPaths(array $spec) : \Zend_Form
Add multiple display group prefix paths at once
ParametersName | Type | Description |
---|
$spec | array | |
---|
Returns 


addDisplayGroups(array $groups) : \Zend_Form
Add multiple display groups at once
ParametersName | Type | Description |
---|
$groups | array | |
---|
Returns 


addElementPrefixPath(string $prefix, string $path, string $type = null) : \Zend_Form
Add prefix path for all elements
ParametersName | Type | Description |
---|
$prefix | string | |
---|
$path | string | |
---|
$type | string | |
---|
Returns 


addElementPrefixPaths(array $spec) : \Zend_Form
Add prefix paths for all elements
ParametersName | Type | Description |
---|
$spec | array | |
---|
Returns 


addElements(array $elements) : \Zend_Form
Add multiple elements at once
ParametersName | Type | Description |
---|
$elements | array | |
---|
Returns 


addError(string $message) : \Zend_Form
Add an error message and mark element as failed validation
ParametersName | Type | Description |
---|
$message | string | |
---|
Returns 


addErrorMessage(string $message) : \Zend_Form
Add a custom error message to return in the event of failed validation
ParametersName | Type | Description |
---|
$message | string | |
---|
Returns 


addErrorMessages(array $messages) : \Zend_Form
Add multiple custom error messages to return in the event of failed validation
ParametersName | Type | Description |
---|
$messages | array | |
---|
Returns 


addErrors(array $messages) : \Zend_Form
Add multiple error messages and flag element as failed validation
ParametersName | Type | Description |
---|
$messages | array | |
---|
Returns 


addPrefixPath(string $prefix, string $path, string $type = null) : \Zend_Form
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'
- elements: $prefix = $prefix . '_Element'
Otherwise, the path prefix is set on the appropriate plugin loader.
If $type is 'decorator', sets the path in the decorator plugin loader
for all elements. Additionally, if no $type is provided,
the prefix and path is added to both decorator and element
plugin loader with following settings:
$prefix . '_Decorator', $path . '/Decorator/'
$prefix . '_Element', $path . '/Element/'
ParametersName | Type | Description |
---|
$prefix | string | |
---|
$path | string | |
---|
$type | string | |
---|
ReturnsThrows


addPrefixPaths(array $spec) : \Zend_Form
Add many prefix paths at once
ParametersName | Type | Description |
---|
$spec | array | |
---|
Returns 


addSubForms(array $subForms) : \Zend_Form
Add multiple form subForms/subforms at once
ParametersName | Type | Description |
---|
$subForms | array | |
---|
Returns 


filterName(string $value, bool $allowBrackets = false) : string
Filter a name to only allow valid variable characters
ParametersName | Type | Description |
---|
$value | string | |
---|
$allowBrackets | bool | |
---|
Returns 


getAttrib(string $key) : mixed
Retrieve a single form attribute
ParametersName | Type | Description |
---|
$key | string | |
---|
Returns 


getElement(string $name) : \Zend_Form_Element | null
Retrieve a single element
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


getElementsAndSubFormsOrdered() : array
Returns a one dimensional numerical indexed array with the
Elements, SubForms and Elements from DisplayGroups as Values.
Subitems are inserted based on their order Setting if set,
otherwise they are appended, the resulting numerical index
may differ from the order value.
ReturnsDetails- Access
- protected



getElementsBelongTo() : string | null
Get name of array elements belong to
ReturnsType | Description |
---|
string | null | |



getErrors(string $name = null, $suppressArrayNotation = false) : array
Get error codes for all elements failing validation
ParametersName | Type | Description |
---|
$name | string | |
---|
$suppressArrayNotation | | |
---|
Returns 


getMessages(string $name = null, bool $suppressArrayNotation = false) : array
Retrieve error messages from elements failing validations
ParametersName | Type | Description |
---|
$name | string | |
---|
$suppressArrayNotation | bool | |
---|
Returns 


getPluginLoader(string $type = null) : \Zend_Loader_PluginLoader_Interface
Retrieve plugin loader for given type
$type may be one of:
- decorator
- element
If a plugin loader does not exist for the given type, defaults are
created.
ParametersName | Type | Description |
---|
$type | string | |
---|
Returns


getSubForm(string $name) : \Zend_Form | null
Retrieve a form subForm/subform
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


getUnfilteredValue(string $name) : mixed
Get unfiltered element value
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


getValidValues(array $data, bool $suppressArrayNotation = false) : array
Returns only the valid values from the given form input.
For models that can be saved in a partially valid state, for example when following the builder,
prototype or state patterns it is particularly interessting to retrieve all the current valid
values to persist them.
ParametersName | Type | Description |
---|
$data | array | |
---|
$suppressArrayNotation | bool | |
---|
Returns


getValue(string $name) : mixed
Retrieve value for single element
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


getValues(bool $suppressArrayNotation = false) : array
Retrieve all form element values
ParametersName | Type | Description |
---|
$suppressArrayNotation | bool | |
---|
Returns 


isErrors() : bool
Are there errors in the form?
ReturnsDetails- Deprecated
- since 1.11.1 - use hasErrors() instead



processAjax(array $data) : string
Process submitted AJAX data
Checks if provided $data is valid, via {@link isValidPartial()}. If so,
it returns JSON-encoded boolean true. If not, it returns JSON-encoded
error messages (as returned by {@link getMessages()}).
ParametersName | Type | Description |
---|
$data | array | |
---|
ReturnsType | Description |
---|
string | JSON-encoded boolean true or error messages |



removeDecorator(string $name) : bool
Remove a single decorator
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


removeDisplayGroup(string $name) : boolean
Remove a display group by name
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


removeFromIteration(string $name) : void
Remove an element from iteration
ParametersName | Type | Description |
---|
$name | string | Element/group/form name |
---|



removeSubForm(string $name) : boolean
Remove form subForm/subform
ParametersName | Type | Description |
---|
$name | string | |
---|
Returns 


setAttribs(array $attribs) : \Zend_Form
Set multiple form attributes at once
Overwrites any previously set attributes.
ParametersName | Type | Description |
---|
$attribs | array | |
---|
Returns


setDefault(string $name, mixed $value) : \Zend_Form
Set default value for an element
ParametersName | Type | Description |
---|
$name | string | |
---|
$value | mixed | |
---|
Returns 


setDefaultDisplayGroupClass(string $class) : \Zend_Form
Set default display group class
ParametersName | Type | Description |
---|
$class | string | |
---|
Returns 


setDefaults(array $defaults) : \Zend_Form
Set default values for elements
Sets values for all elements specified in the array of $defaults.
ParametersName | Type | Description |
---|
$defaults | array | |
---|
Returns


setDisableLoadDefaultDecorators(bool $flag) : \Zend_Form
Set flag to disable loading default decorators
ParametersName | Type | Description |
---|
$flag | bool | |
---|
Returns 


setDisableTranslator(bool $flag) : \Zend_Form
Indicate whether or not translation should be disabled
ParametersName | Type | Description |
---|
$flag | bool | |
---|
Returns 


setDisplayGroupDecorators(array $decorators) : \Zend_Form
Set all display group decorators as specified
ParametersName | Type | Description |
---|
$decorators | array | |
---|
Returns 


setDisplayGroups(array $groups) : \Zend_Form
Add multiple display groups (overwrites)
ParametersName | Type | Description |
---|
$groups | array | |
---|
Returns 


setElementDecorators(array $decorators, array | null $elements = null, bool $include = true) : \Zend_Form
Set all element decorators as specified
ParametersName | Type | Description |
---|
$decorators | array | |
---|
$elements | array | null | Specific elements to decorate or exclude from decoration |
---|
$include | bool | Whether $elements is an inclusion or exclusion list |
---|
Returns 


setElementFilters(array $filters) : \Zend_Form
Set all elements' filters
ParametersName | Type | Description |
---|
$filters | array | |
---|
Returns 


setElements(array $elements) : \Zend_Form
Set form elements (overwrites existing elements)
ParametersName | Type | Description |
---|
$elements | array | |
---|
Returns 


setElementsBelongTo(string $array) : \Zend_Form
Set name of array elements belong to
ParametersName | Type | Description |
---|
$array | string | |
---|
Returns 


setErrorMessages(array $messages) : \Zend_Form
Same as addErrorMessages(), but clears custom error message stack first
ParametersName | Type | Description |
---|
$messages | array | |
---|
Returns 


setErrors(array $messages) : \Zend_Form
Overwrite any previously set error messages and flag as failed validation
ParametersName | Type | Description |
---|
$messages | array | |
---|
Returns 


setIsArray(bool $flag) : \Zend_Form
Set flag indicating elements belong to array
ParametersName | Type | Description |
---|
$flag | bool | Value of flag |
---|
Returns 


setOptions(array $options) : \Zend_Form
Set form state from options array
ParametersName | Type | Description |
---|
$options | array | |
---|
Returns 


setSubFormDecorators(array $decorators) : \Zend_Form
Set all subform decorators as specified
ParametersName | Type | Description |
---|
$decorators | array | |
---|
Returns 


setSubForms(array $subForms) : \Zend_Form
Set multiple form subForms/subforms (overwrites)
ParametersName | Type | Description |
---|
$subForms | array | |
---|
Returns