Allow PATCH method in FormBuilder
This commit is contained in:
1 parent
520d1e6d83
commit
8d46093df3
1 file changed
+13
-6
+13
-6
@@ -62,6 +62,13 @@ class FormBuilder {
|
|||||||
*/
|
*/
|
||||||
protected $reserved = array('method', 'url', 'route', 'action', 'files');
|
protected $reserved = array('method', 'url', 'route', 'action', 'files');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form methods that should be spoofed, in uppercase.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $spoofedMethods = array('DELETE', 'PATCH', 'PUT');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new form builder instance.
|
* Create a new form builder instance.
|
||||||
*
|
*
|
||||||
@@ -89,16 +96,16 @@ class FormBuilder {
|
|||||||
|
|
||||||
// We need to extract the proper method from the attributes. If the method is
|
// We need to extract the proper method from the attributes. If the method is
|
||||||
// something other than GET or POST we'll use POST since we will spoof the
|
// something other than GET or POST we'll use POST since we will spoof the
|
||||||
// actual method since forms don't support PUT or DELETE as native HTML.
|
// actual method since forms don't support PUT, PATCH or DELETE as native HTML.
|
||||||
$attributes['method'] = $this->getMethod($method);
|
$attributes['method'] = $this->getMethod($method);
|
||||||
|
|
||||||
$attributes['action'] = $this->getAction($options);
|
$attributes['action'] = $this->getAction($options);
|
||||||
|
|
||||||
$attributes['accept-charset'] = 'UTF-8';
|
$attributes['accept-charset'] = 'UTF-8';
|
||||||
|
|
||||||
// If the method is PUT or DELETE, we will need to add a spoofer hidden field
|
// If the method is PUT, PATCH or DELETE, we will need to add a spoofer hidden
|
||||||
// that will instruct this Symfony request to pretend that the method is a
|
// field that will instruct this Symfony request to pretend that the method is
|
||||||
// different method than it actually is, for convenience from the forms.
|
// a different method than it actually is, for convenience from the forms.
|
||||||
$append = $this->getAppendage($method);
|
$append = $this->getAppendage($method);
|
||||||
|
|
||||||
if (isset($options['files']) and $options['files'])
|
if (isset($options['files']) and $options['files'])
|
||||||
@@ -108,7 +115,7 @@ class FormBuilder {
|
|||||||
|
|
||||||
// Finally we're ready to create the final form HTML field. We will attribute
|
// Finally we're ready to create the final form HTML field. We will attribute
|
||||||
// format the array of attributes. We will also add on the appendage which
|
// format the array of attributes. We will also add on the appendage which
|
||||||
// is used to spoof the requests for PUT and DELETE requests to the app.
|
// is used to spoof the requests for PUT, PATCH and DELETE requests to the app.
|
||||||
$attributes = array_merge(
|
$attributes = array_merge(
|
||||||
|
|
||||||
$attributes, array_except($options, $this->reserved)
|
$attributes, array_except($options, $this->reserved)
|
||||||
@@ -659,7 +666,7 @@ class FormBuilder {
|
|||||||
{
|
{
|
||||||
$method = strtoupper($method);
|
$method = strtoupper($method);
|
||||||
|
|
||||||
if ($method == 'PUT' or $method == 'DELETE')
|
if (in_array($method, $this->spoofedMethods))
|
||||||
{
|
{
|
||||||
return $this->hidden('_method', $method);
|
return $this->hidden('_method', $method);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user