I am working on a website where an URL is composed after submitting a GET form. The form values are passed as an array of variables of which at least one must b
I recommend you following solution: First, you need to define html form with POST method:
Second, you need to define getSearchTerms
action in your ExampleController
:
public function actionGetSearchTerms()
{
$this->render(Yii::app()->baseUrl.'/example/search/'.$_POST['name']);
}
Then, you need to define main search action:
public function search($name)
{
//do search operation here.
}
Finally, you need to add a url-manager rule:
"example/search/"=>"example/search"
In this solution, getSearchTerms
action is responsible for receiving user entered text, and then pass values to search action. Now your url can be http://localhost/example/search/sampleText
. Note you can skip adding url-manager rule if you like. In this case, your url must be like http://localhost/example/search/name/sampleText
. In fact, we can remove "name" part from url by adding url-manager rule.