4

How I can create URL to Yii form with existing model parameters in URL?

E.g. I have $model with some attributes and want get URL like this:

controller/formaction?Form%5Battr1%5D=VAL1&Form%5Battr2%5D=VAL2
rob006
  • 21,383
  • 5
  • 53
  • 74
elyzov
  • 41
  • 3

3 Answers3

0

There is no way to customize the url when you are using GET method. When you use GET method, browser always concatenates name and value of all inputs with your form action string. So it can't be changed. One possible solution for getting ride of ugly urls, is using POST instead of GET.

hamed
  • 7,939
  • 15
  • 60
  • 114
  • I don't want to change the submitted url of form. I just want create url to the form in another action with attributes in my Form model `$model`. E.g. when I use createUrl function (`$this->createUrl('formaction', $model)`) I get the result like this: `controller/formaction?attr1%5D=VAL1&attr2%5D=VAL2` and it doesn't parsed correctly in `formaction`. – elyzov Jul 06 '15 at 04:54
0

You can generate such URLs in this way:

Yii::app()->createUrl('controller/formaction', [
    CHtml::activeName('Form', 'attr1') => 'VAL1',
    CHtml::activeName('Form', 'attr2') => 'VAL2',
]);
rob006
  • 21,383
  • 5
  • 53
  • 74
-1

Have you try something like this :

public function action formaction(){
  $form = Yii::app()->request->getQuery('Form',false);
}
Renziito
  • 78
  • 3