New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Form] Adding valid
& invalid
form events
#47046
Comments
valid
& invalid
eventsvalid
& invalid
form events
I wrote a Bundle for that. When it would be implemented into the symfony form component. |
We just closed #37641 if you want to have a look. |
@Seb33300 feel free to reuse my code and continue where I left off |
I created a PR: #47210 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
This issue is not a bug but more a discussion about adding new events to the form component.
I am thinking about 2 new events that could occurs after the
form.post_submit
submit event.form.valid
when the entire submitted form is validform.invalid
when at least one item of the submitted form failed to be validThose events will be useful in cases where we need to check that the form passed validation.
Using
$form->isValid()
in theform.post_submit
event only checks that the current form item is valid (not the parents), and we have no easy way to get this information inside a form event.In cases where we need our forms to be used at different places in our application, it could be useful to use those events instead of creating a separate service dedicated to handle them.
Any opinion on this?
Example
But this will also open lot of new possibilities.
As a very simple example, we could attach a listener on the
form.valid
event to persist the entity returned by the form.And re attach this event to all the forms we want.
No need to do this in the controller anymore.
(Not sure this is the best example I can find)
The
form.invalid
event could be used to attach an event dedicated to save metrics about failed form submissions to improve UX of our applications. (analysis of where most customers fail to submit forms)The text was updated successfully, but these errors were encountered: