Symfony\Component\Form\Form
Form represents a form.
To implement your own form fields, you need to have a thorough understanding
of the data flow within a form. A form stores its data in three different
representations:
(1) the "model" format required by the form's object
(2) the "normalized" format for internal processing
(3) the "view" 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 for both internal processing and
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 addViewTransformer().
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
addNormTransformer(). The normalized data is then converted to the displayed
data as described before.
The conversions (1) -> (2) -> (3) use the transform methods of the transformers.
The conversions (3) -> (2) -> (1) use the reverseTransform methods of the transformers.
- Author: Fabien Potencier <fabien@symfony.com>
Synopsis
- // members
- private FormConfigInterface $config;
- private FormInterface $parent;
- private array $children;
- private array $errors;
- private Boolean $submitted;
- private mixed $modelData;
- private mixed $normData;
- private mixed $viewData;
- private array $extraData;
- private Boolean $synchronized;
- private Boolean $defaultDataSet;
- private Boolean $lockSetData;
- // methods
- public void __construct()
- public void __clone()
- public void getConfig()
- public void getName()
- public void getPropertyPath()
- public void isRequired()
- public void isDisabled()
- public void setParent()
- public void getParent()
- public void getRoot()
- public void isRoot()
- public void setData()
- public void getData()
- public void getNormData()
- public void getViewData()
- public void getExtraData()
- public void initialize()
- public void handleRequest()
- public void submit()
- public void bind()
- public void addError()
- public void isSubmitted()
- public void isBound()
- public void isSynchronized()
- public void isEmpty()
- public void isValid()
- public void getErrors()
- public string getErrorsAsString()
- public void all()
- public void add()
- public void remove()
- public void has()
- public void get()
- public Boolean offsetExists()
- public FormInterface offsetGet()
- public void offsetSet()
- public void offsetUnset()
- public ArrayIterator getIterator()
- public integer count()
- public void createView()
- private mixed modelToNorm()
- private mixed normToModel()
- private mixed normToView()
- private mixed viewToNorm()
Hierarchy
Members
private
- $children
—
array
The children of this form - $config
—
Symfony\Component\Form\FormConfigInterface
The form's configuration - $defaultDataSet
—
Symfony\Component\Form\Boolean
Whether the form's data has been initialized. - $errors
—
array
The errors of this form - $extraData
—
array
The submitted values that don't belong to any children - $lockSetData
—
Symfony\Component\Form\Boolean
Whether setData() is currently being called. - $modelData
—
mixed
The form data in model format - $normData
—
mixed
The form data in normalized format - $parent
—
Symfony\Component\Form\FormInterface
The parent of this form - $submitted
—
Symfony\Component\Form\Boolean
Whether this form was submitted - $synchronized
—
Symfony\Component\Form\Boolean
Whether the data in model, normalized and view format is synchronized. Data may not be synchronized if transformation errors occur. - $viewData
—
mixed
The form data in view format
Methods
private
- modelToNorm() — Normalizes the value if a normalization transformer is set.
- normToModel() — Reverse transforms a value if a normalization transformer is set.
- normToView() — Transforms the value if a value transformer is set.
- viewToNorm() — Reverse transforms a value if a value transformer is set.
public
- __construct() — Creates a new form based on the given configuration.
- __clone()
- add() — {@inheritdoc}
- addError() — {@inheritdoc}
- all() — {@inheritdoc}
- bind() — Alias of {@link submit()}.
- count() — Returns the number of form children (implements the \Countable interface).
- createView() — {@inheritdoc}
- get() — {@inheritdoc}
- getConfig() — {@inheritdoc}
- getData() — {@inheritdoc}
- getErrors() — {@inheritdoc}
- getErrorsAsString() — Returns a string representation of all form errors (including children errors).
- getExtraData() — {@inheritdoc}
- getIterator() — Returns the iterator for this group.
- getName() — {@inheritdoc}
- getNormData() — {@inheritdoc}
- getParent() — {@inheritdoc}
- getPropertyPath() — {@inheritdoc}
- getRoot() — {@inheritdoc}
- getViewData() — {@inheritdoc}
- handleRequest() — {@inheritdoc}
- has() — {@inheritdoc}
- initialize() — {@inheritdoc}
- isBound() — Alias of {@link isSubmitted()}.
- isDisabled() — {@inheritDoc}
- isEmpty() — {@inheritdoc}
- isRequired() — {@inheritdoc}
- isRoot() — {@inheritdoc}
- isSubmitted() — {@inheritdoc}
- isSynchronized() — {@inheritdoc}
- isValid() — {@inheritdoc}
- offsetExists() — Returns whether a child with the given name exists (implements the \ArrayAccess interface).
- offsetGet() — Returns the child with the given name (implements the \ArrayAccess interface).
- offsetSet() — Adds a child to the form (implements the \ArrayAccess interface).
- offsetUnset() — Removes the child with the given name from the form (implements the \ArrayAccess interface).
- remove() — {@inheritdoc}
- setData() — {@inheritdoc}
- setParent() — {@inheritdoc}
- submit() — {@inheritdoc}