feature/formΒΆ
DescriptionΒΆ
This feature extends the default UserFormType used in Lodel to introduce a new civility field and customize form submission behavior β without altering the original form class or template.
It adds:
A new unmapped radio field called civility with choices:
Mr.,Mrs.,MissornoneAn event subscriber that listens to the
PRE_SUBMITphase and prepends the selectedcivilityto the userβs last name
The extension is seamlessly integrated into the existing form and does not require any manual template updates or controller changes.
File structureΒΆ
HelloWorldBundle/
βββ src/
β βββ EventSubscriber/
β β βββ UserFormSubmitSubscriber.php # Modifies form data during the PRE_SUBMIT event
β βββ Form/
β βββ UserFormTypeExtension.php # Extends the original UserFormType to add the "civility" field
β βββ Resources/
β βββ config/
β βββ services.yaml # Declares and tags the form extension and subscriber
Internal ImplementationΒΆ
This feature is composed of the following elements:
Form Type Extension (
UserFormTypeExtension): Adds acivilityradio field (unmapped) to the form and attaches the custom event subscriber.Event Subscriber (
UserFormSubmitSubscriber): Listens toFormEvents::PRE_SUBMITand prepends the selectedcivilityto the submitted lastName field.Service Configuration (
services.yaml): Registers the form type extension and event subscriber with the appropriate tags for Symfony to recognize and apply them automatically.
How to useΒΆ
You will see the additional "Civility" field appear, and it will automatically influence the submitted lastName without any modification to the original form or template.