Skip to content

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

@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