HTML forms natively support only GET and POST requests. To enable RESTful actions like DELETE, PUT, and PATCH, we need a mechanism to translate form submissions into their intended HTTP methods. This would help to resolve #184.
Proposal
Introduce a MethodOverride middleware that intercepts form-data POST requests. This middleware should:
Check for _method Field: Examine if the request contains an input field named _method.
Override Request Method: If _method exists, override the request method with the specified value (e.g., DELETE, PUT, PATCH).
Configurable Allowed Methods: Provide a method like allowed_override_methods returning an array of permitted HTTP methods for overriding. This array should be customizable to control which methods can be used.
I think that a method_input template tag would be more consistent with other template tags that generate form inputs (such as the csrf_input one). For example:
Description
HTML forms natively support only GET and POST requests. To enable RESTful actions like DELETE, PUT, and PATCH, we need a mechanism to translate form submissions into their intended HTTP methods. This would help to resolve #184.
Proposal
Introduce a
MethodOverride
middleware that intercepts form-data POST requests. This middleware should:_method
Field: Examine if the request contains an input field named_method
._method
exists, override the request method with the specified value (e.g., DELETE, PUT, PATCH).allowed_override_methods
returning an array of permitted HTTP methods for overriding. This array should be customizable to control which methods can be used.Example Usage:
Considerations
Implement tag helper, e.g.
{% form_delete %}
, to help reduce the chance of typos being made.