interface FormInterface implements ArrayAccess, Traversable, Countable

A form group bundling multiple forms in a hierarchical structure.

Methods

setParent(FormInterface $parent = null)

Sets the parent form.

getParent()

Returns the parent form.

add(FormInterface|string|int $child, string|null $type = null, array $options = array())

Adds or replaces a child to the form.

get(string $name)

Returns the child with the given name.

bool
has(string $name)

Returns whether a child with the given name exists.

remove(string $name)

Removes a child from the form.

all()

Returns all children in this group.

getErrors(bool $deep = false, bool $flatten = true)

Returns the errors of this form.

setData(mixed $modelData)

Updates the form with default data.

mixed
getData()

Returns the data in the format needed for the underlying object.

mixed
getNormData()

Returns the normalized data of the field.

mixed
getViewData()

Returns the data transformed by the value transformer.

array
getExtraData()

Returns the extra data.

getConfig()

Returns the form's configuration.

bool
isSubmitted()

Returns whether the form is submitted.

string
getName()

Returns the name by which the form is identified in forms.

getPropertyPath()

Returns the property path that the form is mapped to.

addError(FormError $error)

Adds an error to this form.

bool
isValid()

Returns whether the form and all children are valid.

bool
isRequired()

Returns whether the form is required to be filled out.

bool
isDisabled()

Returns whether this form is disabled.

bool
isEmpty()

Returns whether the form is empty.

bool
isSynchronized()

Returns whether the data in the different formats is synchronized.

getTransformationFailure()

Returns the data transformation failure, if any.

initialize()

Initializes the form tree.

handleRequest(mixed $request = null)

Inspects the given request and calls {@link submit()} if the form was submitted.

submit(null|string|array $submittedData, bool $clearMissing = true)

Submits data to the form, transforms and validates it.

getRoot()

Returns the root of the form tree.

bool
isRoot()

Returns whether the field is the root of the form tree.

createView(FormView $parent = null)

Creates a view.

Details

at line line 34
FormInterface setParent(FormInterface $parent = null)

Sets the parent form.

Parameters

FormInterface $parent The parent form or null if it's the root.

Return Value

FormInterface The form instance

Exceptions

AlreadySubmittedException If the form has already been submitted.
LogicException When trying to set a parent for a form with an empty name.

at line line 41
FormInterface|null getParent()

Returns the parent form.

Return Value

FormInterface|null The parent form or null if there is none.

at line line 56
FormInterface add(FormInterface|string|int $child, string|null $type = null, array $options = array())

Adds or replaces a child to the form.

Parameters

FormInterface|string|int $child The FormInterface instance or the name of the child.
string|null $type The child's type, if a name was passed.
array $options The child's options, if a name was passed.

Return Value

FormInterface The form instance

Exceptions

AlreadySubmittedException If the form has already been submitted.
LogicException When trying to add a child to a non-compound form.
UnexpectedTypeException If $child or $type has an unexpected type.

at line line 67
FormInterface get(string $name)

Returns the child with the given name.

Parameters

string $name The name of the child

Return Value

FormInterface The child form

Exceptions

OutOfBoundsException If the named child does not exist.

at line line 76
bool has(string $name)

Returns whether a child with the given name exists.

Parameters

string $name The name of the child

Return Value

bool

at line line 87
FormInterface remove(string $name)

Removes a child from the form.

Parameters

string $name The name of the child to remove

Return Value

FormInterface The form instance

Exceptions

AlreadySubmittedException If the form has already been submitted.

at line line 94
FormInterface[] all()

Returns all children in this group.

Return Value

FormInterface[] An array of FormInterface instances

at line line 109
FormErrorIterator getErrors(bool $deep = false, bool $flatten = true)

Returns the errors of this form.

Parameters

bool $deep Whether to include errors of child forms as well
bool $flatten Whether to flatten the list of errors in case $deep is set to true

Return Value

FormErrorIterator An iterator over the {@link FormError} instances that where added to this form

at line line 123
FormInterface setData(mixed $modelData)

Updates the form with default data.

Parameters

mixed $modelData The data formatted as expected for the underlying object

Return Value

FormInterface The form instance

Exceptions

AlreadySubmittedException If the form has already been submitted.
LogicException If listeners try to call setData in a cycle. Or if the view data does not match the expected type according to {@link FormConfigInterface::getDataClass}.

at line line 130
mixed getData()

Returns the data in the format needed for the underlying object.

Return Value

mixed

at line line 139
mixed getNormData()

Returns the normalized data of the field.

Return Value

mixed When the field is not submitted, the default data is returned. When the field is submitted, the normalized submitted data is returned if the field is valid, null otherwise.

at line line 146
mixed getViewData()

Returns the data transformed by the value transformer.

Return Value

mixed

at line line 153
array getExtraData()

Returns the extra data.

Return Value

array The submitted data which do not belong to a child

at line line 160
FormConfigInterface getConfig()

Returns the form's configuration.

Return Value

FormConfigInterface The configuration.

at line line 167
bool isSubmitted()

Returns whether the form is submitted.

Return Value

bool true if the form is submitted, false otherwise

at line line 174
string getName()

Returns the name by which the form is identified in forms.

Return Value

string The name of the form.

at line line 181
PropertyPathInterface getPropertyPath()

Returns the property path that the form is mapped to.

Return Value

PropertyPathInterface The property path.

at line line 190
FormInterface addError(FormError $error)

Adds an error to this form.

Parameters

FormError $error

Return Value

FormInterface The form instance

at line line 199
bool isValid()

Returns whether the form and all children are valid.

If the form is not submitted, this method always returns false (but will throw an exception in 4.0).

Return Value

bool

at line line 210
bool 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.

Return Value

bool

at line line 223
bool isDisabled()

Returns whether this form is disabled.

The content of a disabled form is displayed, but not allowed to be modified. The validation of modified disabled forms should fail.

Forms whose parents are disabled are considered disabled regardless of their own state.

Return Value

bool

at line line 230
bool isEmpty()

Returns whether the form is empty.

Return Value

bool

at line line 240
bool isSynchronized()

Returns whether the data in the different formats is synchronized.

If the data is not synchronized, you can get the transformation failure by calling {@link getTransformationFailure()}.

Return Value

bool

at line line 247
TransformationFailedException|null getTransformationFailure()

Returns the data transformation failure, if any.

Return Value

TransformationFailedException|null The transformation failure

at line line 256
FormInterface initialize()

Initializes the form tree.

Should be called on the root form after constructing the tree.

Return Value

FormInterface The form instance.

at line line 270
FormInterface handleRequest(mixed $request = null)

Inspects the given request and calls {@link submit()} if the form was submitted.

Internally, the request is forwarded to the configured {@link RequestHandlerInterface} instance, which determines whether to submit the form or not.

Parameters

mixed $request The request to handle.

Return Value

FormInterface The form instance.

at line line 284
FormInterface submit(null|string|array $submittedData, bool $clearMissing = true)

Submits data to the form, transforms and validates it.

Parameters

null|string|array $submittedData The submitted data.
bool $clearMissing Whether to set fields to NULL when they are missing in the submitted data.

Return Value

FormInterface The form instance

Exceptions

AlreadySubmittedException If the form has already been submitted.

at line line 291
FormInterface getRoot()

Returns the root of the form tree.

Return Value

FormInterface The root of the tree

at line line 298
bool isRoot()

Returns whether the field is the root of the form tree.

Return Value

bool

at line line 307
FormView createView(FormView $parent = null)

Creates a view.

Parameters

FormView $parent The parent view

Return Value

FormView The view