Replace GET parameters when changed
This commit is contained in:
parent
d5a8a1009b
commit
fa9fb5c1ce
@ -197,9 +197,18 @@ class Form extends Link implements \ArrayAccess
|
|||||||
{
|
{
|
||||||
$uri = parent::getUri();
|
$uri = parent::getUri();
|
||||||
|
|
||||||
if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH')) && $queryString = http_build_query($this->getValues(), null, '&')) {
|
if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) {
|
||||||
$sep = false === strpos($uri, '?') ? '?' : '&';
|
$query = parse_url($uri, PHP_URL_QUERY);
|
||||||
$uri .= $sep.$queryString;
|
$currentParameters = array();
|
||||||
|
if ($query) {
|
||||||
|
parse_str($query, $currentParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
$queryString = http_build_query(array_merge($currentParameters, $this->getValues()), null, '&');
|
||||||
|
|
||||||
|
$pos = strpos($uri, '?');
|
||||||
|
$base = false === $pos ? $uri : substr($uri, 0, $pos);
|
||||||
|
$uri = rtrim($base.'?'.$queryString, '?');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $uri;
|
return $uri;
|
||||||
|
@ -573,6 +573,12 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(),
|
array(),
|
||||||
'/foo?bar=bar&foo=foo',
|
'/foo?bar=bar&foo=foo',
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'replaces query values with the form values',
|
||||||
|
'<form action="/foo?bar=bar"><input type="text" name="bar" value="foo" /><input type="submit" /></form>',
|
||||||
|
array(),
|
||||||
|
'/foo?bar=foo',
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'returns an empty URI if the action is empty',
|
'returns an empty URI if the action is empty',
|
||||||
'<form><input type="submit" /></form>',
|
'<form><input type="submit" /></form>',
|
||||||
|
Reference in New Issue
Block a user