Hi, i am using the _search file that is generated by gii. I use it as search form for gridview in index page.
This _search file is using activeform.
According to the activeform guide
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activeform#$action-detail
The form action URL. This parameter will be processed by yii\helpers\Url::to().
So according to the to() detail
https://www.yiiframework.com/doc/api/2.0/yii-helpers-baseurl#to()-detail
// /index.php?r=site%2Findex&src=ref1#name
echo Url::to([‘site/index’, ‘src’ => ‘ref1’, ‘#’ => ‘name’]);
It should be able to create url with #name at the end of the url like example above. But it has problem when do that with the active form in the _search file, probably because it use get method which causing it to append the form field name and value after the #name.
For example, in this case i display an index page of a model inside the view page of another model
<?php $form = ActiveForm::begin([
‘action’ => [
‘action1/view’,
‘id’ => 1,
‘#’ => ‘section1’
],
‘method’ => ‘get’,
]); ?>
and the form contain 2 filter field like field1 and field2.
After submit the form, i am expecting the #section to be at the end of the url.
Instead, the url will be like action1/view?id=1%23section1&field1=something&field2=something.
So the #section is not working. And the value of id will be wrong as well.
To make it work, i do this
<?php $form = ActiveForm::begin([
‘action’ => [
‘action1/view#section1’,
‘id’ => 1,
],
‘method’ => ‘get’,
]); ?>
It is not big problem, just want to share the solution and i also want to know other people opinion on this matter.