Documentation

FormEvents
in package

FinalYes

To learn more about how form events work check the documentation entry at {@link https://symfony.com/doc/any/components/form/form_events.html}.

To learn how to dynamically modify forms using events check the cookbook entry at .

Tags
author

Bernhard Schussek bschussek@gmail.com

Table of Contents

Constants

ALIASES  = [\Symfony\Component\Form\Event\PreSubmitEvent::class => self::PRE_SUBMIT, \Symfony\Component\Form\Event\SubmitEvent::class => self::SUBMIT, \Symfony\Component\Form\Event\PostSubmitEvent::class => self::POST_SUBMIT, \Symfony\Component\Form\Event\PreSetDataEvent::class => self::PRE_SET_DATA, \Symfony\Component\Form\Event\PostSetDataEvent::class => self::POST_SET_DATA]
Event aliases.
POST_SET_DATA  = 'form.post_set_data'
The FormEvents::POST_SET_DATA event is dispatched at the end of the Form::setData() method.
POST_SUBMIT  = 'form.post_submit'
The FormEvents::POST_SUBMIT event is dispatched at the very end of the Form::submit().
PRE_SET_DATA  = 'form.pre_set_data'
The FormEvents::PRE_SET_DATA event is dispatched at the beginning of the Form::setData() method.
PRE_SUBMIT  = 'form.pre_submit'
The PRE_SUBMIT event is dispatched at the beginning of the Form::submit() method.
SUBMIT  = 'form.submit'
The SUBMIT event is dispatched after the Form::submit() method has changed the view data by the request data, or submitted and mapped the children if the form is compound, and after reverse transformation to normalized representation.

Methods

__construct()  : mixed

Constants

ALIASES

Event aliases.

public mixed ALIASES = [\Symfony\Component\Form\Event\PreSubmitEvent::class => self::PRE_SUBMIT, \Symfony\Component\Form\Event\SubmitEvent::class => self::SUBMIT, \Symfony\Component\Form\Event\PostSubmitEvent::class => self::POST_SUBMIT, \Symfony\Component\Form\Event\PreSetDataEvent::class => self::PRE_SET_DATA, \Symfony\Component\Form\Event\PostSetDataEvent::class => self::POST_SET_DATA]

These aliases can be consumed by RegisterListenersPass.

POST_SET_DATA

The FormEvents::POST_SET_DATA event is dispatched at the end of the Form::setData() method.

public mixed POST_SET_DATA = 'form.post_set_data'

This event can be used to modify the form depending on the final state of the underlying data accessible in every representation: model, normalized and view.

Tags
Event

("Symfony\Component\Form\Event\PostSetDataEvent")

POST_SUBMIT

The FormEvents::POST_SUBMIT event is dispatched at the very end of the Form::submit().

public mixed POST_SUBMIT = 'form.post_submit'

It this stage the model and view data may have been denormalized. Otherwise the form is desynchronized because transformation failed during submission.

It can be used to fetch data after denormalization.

The event attaches the current view data. To know whether this is the renormalized data or the invalid request data, call Form::isSynchronized() first.

Tags
Event

("Symfony\Component\Form\Event\PostSubmitEvent")

PRE_SET_DATA

The FormEvents::PRE_SET_DATA event is dispatched at the beginning of the Form::setData() method.

public mixed PRE_SET_DATA = 'form.pre_set_data'

It can be used to:

  • Modify the data given during pre-population;
  • Keep synchronized the form depending on the data (adding or removing fields dynamically).
Tags
Event

("Symfony\Component\Form\Event\PreSetDataEvent")

PRE_SUBMIT

The PRE_SUBMIT event is dispatched at the beginning of the Form::submit() method.

public mixed PRE_SUBMIT = 'form.pre_submit'

It can be used to:

  • Change data from the request, before submitting the data to the form.
  • Add or remove form fields, before submitting the data to the form.
Tags
Event

("Symfony\Component\Form\Event\PreSubmitEvent")

SUBMIT

The SUBMIT event is dispatched after the Form::submit() method has changed the view data by the request data, or submitted and mapped the children if the form is compound, and after reverse transformation to normalized representation.

public mixed SUBMIT = 'form.submit'

It's also dispatched just before the Form::submit() method transforms back the normalized data to the model and view data.

So at this stage children of compound forms are submitted and synchronized, unless their transformation failed, but a parent would still be at the PRE_SUBMIT level.

Since the current form is not synchronized yet, it is still possible to add and remove fields.

Tags
Event

("Symfony\Component\Form\Event\SubmitEvent")

Methods


        
On this page

Search results