Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@alexander-schranz

Description

@alexander-schranz
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.