So a user is directed to a page in my ZF2 app as follows:
http://example.com/some/route/variable?auth=1234&channel=1234&tz=1234&locale=&client=1234
The controller loads a form:
if ($prg instanceof Response) {
return $prg
} elseif ($prg === false) {
return new ViewModel([
'form' => $this->transferForm,
]);
}
And in the view:
$form = $this->form;
$form->setAttribute('action', $this->url('some/route',[],true));
$form->setAttribute('method', 'post');
What I want to happen is when the user invokes the form that it posts to the same inbound route, namely:
http://example.com/some/route/variable?auth=1234&channel=1234&tz=1234&locale=&client=1234
Is there a stupidly simple way of doing this?
Or do I need to get each param, and explicityly place them in the form target uri?:
$form->setAttribute('action', $this->url('some/route',[],[query => [''] ]));
As it stands I have written a helper to deal with this:
namespace Some\View\Helper;
use Zend\View\Helper\AbstractHelper;
class ParamsHelper extends AbstractHelper {
public function __invoke()
{
$param1 = (isset($_GET['param1'])) ? $_GET['param1'] : '';
$param2 = (isset($_GET['param2'])) ? $_GET['param2'] : '';
$param3 = (isset($_GET['param3'])) ? $_GET['param3'] : '';
$param4 = (isset($_GET['param4'])) ? $_GET['param4'] : '';
$param5 = (isset($_GET['param5'])) ? $_GET['param5'] : '';
$queryParams = (null == $auth) ? [] : ['query' =>
[
'param1' => $param1 ,
'param2' => $param2 ,
'param3' => $param3 ,
'param4' => $param4,
'param5' => $param5
]
];
return $queryParams;
}
}
This resolves the issue however it still seems a longwinded and not so dynamic way of resolving the issue...