Skip to content
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 validation errors result in 400 Response #49

Open
datenwerk-at opened this issue Nov 27, 2023 · 3 comments
Open

Form validation errors result in 400 Response #49

datenwerk-at opened this issue Nov 27, 2023 · 3 comments

Comments

@datenwerk-at
Copy link

Q A
Bug? yes
New Feature? no
Sulu Version Bundle 2.0.0; Sulu 2.5.10

Actual Behavior

When Comment-form validation fails a 400-http-Response is sent back.

Expected Behavior

Comments form with validation errors is shown.

Steps to Reproduce

Extend Comment entity and CommentForm type and add a property with some constraint (eg. NotBlank).
On submission of empty form the validation fails and a "Bad Request" Response (400) is sent back to the client.

Possible Solutions

Change form-action to referrer and let the form handle the request there?

@Prokyonn
Copy link
Member

Prokyonn commented Nov 28, 2023

Hey @datenwerk-at, thank you for reporting the issue.

I investigated it, but I need you to confirm, if I understood it correctly :)

As far as I understand it, the issue is, that you get a 400 request instead of the rendered form with the error, is that correct?

I assume you want the error to be rendered in the form to give the user some kind of feedback. Furthermore the data should also not be lost right?

@alexander-schranz
Copy link
Member

alexander-schranz commented Nov 28, 2023

Think we need here:

return new Response(null, 400);

Render the form containing the errors, in case the request is from requestFormat html. The response status code we should change to 422, if somebody uses hotwired turbo that status code would be required.

The more technical task here is that we need define a error format for JSON requests as in some projects the API is also used via JSON instead of symfony forms. There we maybe can orientated at the following issue: sulu/sulu#5809 (comment)

@datenwerk-at
Copy link
Author

Hi guys, thanks for your comments.

As far as I understand it, the issue is, that you get a 400 request instead of the rendered form with the error, is that correct?

I assume you want the error to be rendered in the form to give the user some kind of feedback. Furthermore the data should also not be lost right?

That's exactly right.
And I think that Alex' outlined solution absolutely points in the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants