-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Cannot submit form with custom HTTP method #26287
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
Comments
Can you please show the code you used and the full exception with a stack trace included that you got with that? |
Controller: /**
* @Route(path="/users", methods={"RESET"})
*/
public function resetAction(Request $request)
{
$builder = $this
->createFormBuilder([], [
'method' => 'RESET',
])
->add('id', IntegerType::class);
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// ...
}
return new Response();
} Stacktrace:
|
Ah, I read your initial description too fast. That's indeed something that is not supported right now. |
Oh, i thought it was simply a wrong check. |
Why don't you use standard verbs? POST can do pretty much anything. I'm not sure it make sense to support this in Symfony. We've always been standards first. Might seem small, but the current restriction eg helps detect typos, which is important for DX. |
When implementing an API maybe a POST request does not describe your needs well enough. |
Considering this is something specific for the form framework, I would argue that you shouldn't be using forms for apis in the first place. |
If I may, why not? Forms are powerful, highly configurable, event emitting and self-validating data mappers, why shouldn't be used? You can transform data, validate data even change the configuration of the form based on the data received by the client with a minimum effort. |
Why not, that's correct :) |
Sure! I've opened a PR, but I'm not sure if this is the best possibile solution of the problem. I look forward to hear your feedbacks |
…tion (alekitto) This PR was merged into the 4.2-dev branch. Discussion ---------- [Form] allow additional http methods in form configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26287 | License | MIT | Doc PR | TBD In order to allow HTTP methods other than GET, PUT, POST, DELETE and PATCH, the `allowed_methods` option under `framework.form` configuration has been added. This configuration option adds the specified methods to the `FormConfigBuilder` whitelist, allowing that methods be used in form configuration via `setMethod` or the `method` option. The use-case, that has been discussed in #26287, required the usage of custom HTTP method for describing a resource in an API application. Commits ------- 27d228c [Form] remove restriction on allowed http methods
Uh oh!
There was an error while loading. Please reload this page.
While the routing component correctly handles custom HTTP methods, the form component disallow configuring a form with a method which is not
GET
,PUT
,POST
,DELETE
,PATCH
.When trying to create an action with a custom HTTP method,
FormConfigBuilder::setMethod
throws an InvalidArgumentException.The text was updated successfully, but these errors were encountered: