Skip to content

[Form] Add a method to submit a request and return the valid method in one #59537

Open
@alexander-schranz

Description

@alexander-schranz

Description

I think for developer experience it would be nice if there would be a method which is doing handleRequest and returning the valid state in one method.

Example

Most form controller looks like this:

$form = $this->formFactory->create(...);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
    // Do something
}

I think it would be better for DX to have something like:

$form = $this->formFactory->create(...);

if ($form->handleRequestAndValid($request)) {
    // Do something
}

Another possibility would be change the handleRequest to match more this common usage, currently via a BC layer example like:

$form = $this->formFactory->create(...);

if ($form->handleRequest($request, validate: true)) {
    // Do something
}

Update

After some discussion in the comment I think best would be:

$form = $this->formFactory->create(...);

if ($form->handleRequest($request)->isSubmittedAndIsValid()) {
    // Do something
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy