Skip to content

[Form] Adding valid & invalid form events #47046

Closed
@Seb33300

Description

@Seb33300

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.

  1. form.valid when the entire submitted form is valid
  2. form.invalid when at least one item of the submitted form failed to be valid

Those events will be useful in cases where we need to check that the form passed validation.
Using $form->isValid() in the form.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

  • This could significantly reduce the complexity of this PR where I hash a password only when the form is valid.

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions