class Form implements IteratorAggregate, FormInterface
Form represents a form.
A form is composed of a validator schema and a widget form schema.
To implement your own form fields, you need to have a thorough understanding
of the data flow within a form field. A form field stores its data in three
different representations:
(1) the format required by the form's object
(2) a normalized format for internal processing
(3) the format used for display
A date field, for example, may store a date as "Y-m-d" string (1) in the
object. To facilitate processing in the field, this value is normalized
to a DateTime object (2). In the HTML representation of your form, a
localized string (3) is presented to and modified by the user.
In most cases, format (1) and format (2) will be the same. For example,
a checkbox field uses a Boolean value both for internal processing as for
storage in the object. In these cases you simply need to set a value
transformer to convert between formats (2) and (3). You can do this by
calling appendClientTransformer().
In some cases though it makes sense to make format (1) configurable. To
demonstrate this, let's extend our above date field to store the value
either as "Y-m-d" string or as timestamp. Internally we still want to
use a DateTime object for processing. To convert the data from string/integer
to DateTime you can set a normalization transformer by calling
appendNormTransformer(). The normalized data is then
converted to the displayed data as described before.
Methods
| __construct($name, EventDispatcherInterface $dispatcher, array $types = array(), array $clientTransformers = array(), array $normTransformers = array(), DataMapperInterface $dataMapper = null, array $validators = array(), $required = false, $readOnly = false, $errorBubbling = false, $emptyData = null, array $attributes = array()) | ||
| __clone() | ||
| string |
getName()
Returns the name by which the form is identified in forms. |
|
| array |
getTypes()
Returns the supported types. |
|
| Boolean |
isRequired()
Returns whether the form is required to be filled out. |
|
| Boolean |
isReadOnly()
Returns whether this form can be read only. |
|
| Form |
setParent(FormInterface $parent = null)
Sets the parent form. |
|
| FormInterface |
getParent()
Returns the parent form. |
|
| Boolean |
hasParent()
Returns whether the form has a parent. |
|
| FormInterface |
getRoot()
Returns the root of the form tree. |
|
| Boolean |
isRoot()
Returns whether the field is the root of the form tree. |
|
| Boolean |
hasAttribute(string $name)
Returns whether the form has an attribute with the given name. |
|
|
getAttribute(string $name)
Returns the value of the attributes with the given name. |
||
| Form |
setData(array $appData)
Updates the field with default data. |
|
| mixed |
getData()
Returns the data in the format needed for the underlying object. |
|
| string |
getClientData()
Returns the data transformed by the value transformer. |
|
| array |
getExtraData()
Returns the extra data. |
|
| Form |
bind(string|array $clientData)
Writes data into the form. |
|
| Form |
bindRequest(Request $request)
Binds a request to the form. |
|
| mixed |
getNormData()
Returns the normalized data of the field. |
|
| Form |
addError(FormError $error)
Adds an error to this form. |
|
| Boolean |
getErrorBubbling()
Returns whether errors bubble up to the parent. |
|
| Boolean |
isBound()
Returns whether the field is bound. |
|
| Boolean |
isSynchronized()
Returns whether the data in the different formats is synchronized. |
|
| Boolean |
isEmpty()
Returns whether the form is empty. |
|
| Boolean |
isValid()
Returns whether the form is valid. |
|
| Boolean |
hasErrors()
Returns whether or not there are errors. |
|
| array |
getErrors()
Returns all errors. |
|
| array |
getNormTransformers()
Returns the DataTransformers. |
|
| array |
getClientTransformers()
Returns the DataTransformers. |
|
| array |
getChildren()
Returns all children in this group. |
|
| Boolean |
hasChildren()
Return whether the form has children. |
|
| Form |
add(FormInterface $child)
Adds a child to the form. |
|
| Form |
remove(string $name)
Removes a child from the form. |
|
| Boolean |
has(string $name)
Returns whether a child with the given name exists. |
|
| FormInterface |
get(string $name)
Returns the child with the given name. |
|
| Boolean |
offsetExists(string $name)
Returns true if the child exists (implements the \ArrayAccess interface). |
|
| FormInterface |
offsetGet(string $name)
Returns the form child associated with the name (implements the \ArrayAccess interface). |
|
|
offsetSet(string $name, FormInterface $child)
Adds a child to the form (implements the \ArrayAccess interface). |
||
|
offsetUnset(string $name)
Removes the child with the given name from the form (implements the \ArrayAccess interface). |
||
| ArrayIterator |
getIterator()
Returns the iterator for this group. |
|
| integer |
count()
Returns the number of form children (implements the \Countable interface). |
|
| FormView |
createView(FormView $parent = null)
Creates a view. |
Details
at line 189
public
__construct($name, EventDispatcherInterface $dispatcher, array $types = array(), array $clientTransformers = array(), array $normTransformers = array(), DataMapperInterface $dataMapper = null, array $validators = array(), $required = false, $readOnly = false, $errorBubbling = false, $emptyData = null, array $attributes = array())
at line 230
public
__clone()
at line 242
public string
getName()
Returns the name by which the form is identified in forms.
at line 252
public array
getTypes()
Returns the supported types.
at line 266
public Boolean
isRequired()
Returns whether the form is required to be filled out.
If the form has a parent and the parent is not required, this method
will always return false. Otherwise the value set with setRequired()
is returned.
at line 287
public Boolean
isReadOnly()
Returns whether this form can be read only.
The content of a read-only form is displayed, but not allowed to be
modified. The validation of modified read-only forms should fail.
Fields whose parents are read-only are considered read-only regardless of
their own state.
at line 304
public Form
setParent(FormInterface $parent = null)
Sets the parent form.
at line 316
public FormInterface
getParent()
Returns the parent form.
at line 326
public Boolean
hasParent()
Returns whether the form has a parent.
at line 336
public FormInterface
getRoot()
Returns the root of the form tree.
at line 346
public Boolean
isRoot()
Returns whether the field is the root of the form tree.
at line 358
public Boolean
hasAttribute(string $name)
Returns whether the form has an attribute with the given name.
at line 368
public
getAttribute(string $name)
Returns the value of the attributes with the given name.
at line 380
public Form
setData(array $appData)
Updates the field with default data.
at line 420
public mixed
getData()
Returns the data in the format needed for the underlying object.
at line 430
public string
getClientData()
Returns the data transformed by the value transformer.
at line 440
public array
getExtraData()
Returns the extra data.
at line 454
public Form
bind(string|array $clientData)
Writes data into the form.
at line 574
public Form
bindRequest(Request $request)
Binds a request to the form.
If the request method is POST, PUT or GET, the data is bound to the form,
transformed and written into the form data (an object or an array).
at line 602
public mixed
getNormData()
Returns the normalized data of the field.
at line 614
public Form
addError(FormError $error)
Adds an error to this form.
at line 630
public Boolean
getErrorBubbling()
Returns whether errors bubble up to the parent.
at line 640
public Boolean
isBound()
Returns whether the field is bound.
at line 650
public Boolean
isSynchronized()
Returns whether the data in the different formats is synchronized.
at line 660
public Boolean
isEmpty()
Returns whether the form is empty.
at line 677
public Boolean
isValid()
Returns whether the form is valid.
at line 704
public Boolean
hasErrors()
Returns whether or not there are errors.
at line 718
public array
getErrors()
Returns all errors.
at line 728
public array
getNormTransformers()
Returns the DataTransformers.
at line 738
public array
getClientTransformers()
Returns the DataTransformers.
at line 748
public array
getChildren()
Returns all children in this group.
at line 758
public Boolean
hasChildren()
Return whether the form has children.
at line 770
public Form
add(FormInterface $child)
Adds a child to the form.
at line 790
public Form
remove(string $name)
Removes a child from the form.
at line 808
public Boolean
has(string $name)
Returns whether a child with the given name exists.
at line 822
public FormInterface
get(string $name)
Returns the child with the given name.
at line 839
public Boolean
offsetExists(string $name)
Returns true if the child exists (implements the \ArrayAccess interface).
at line 851
public FormInterface
offsetGet(string $name)
Returns the form child associated with the name (implements the \ArrayAccess interface).
at line 862
public
offsetSet(string $name, FormInterface $child)
Adds a child to the form (implements the \ArrayAccess interface).
at line 872
public
offsetUnset(string $name)
Removes the child with the given name from the form (implements the \ArrayAccess interface).
at line 882
public ArrayIterator
getIterator()
Returns the iterator for this group.
at line 892
public integer
count()
Returns the number of form children (implements the \Countable interface).
at line 904
public FormView
createView(FormView $parent = null)
Creates a view.