Basic Form Feature

I have a search form on my index page.


<form action="<?=$this->createUrl(array('search/result'))?>" method="POST">

<div>

	<input type="text" name="search">

</div>

Now it’s creating this HTML code :


<form action="/project/index.php?r=search/result" method="POST">

<div>

	<input type="text" name="search">

</div>

And this is result action of Search.


public function actionSonuc()

{

	$criteria = new CDbCriteria;

	$criteria->condition = "`name` LIKE '%".$_POST["search"]."%'";

	$query = Otel::model()->findAll($criteria);

	$this->render('result', array("query" => $query));

}

Everything is OK. BUT as you see, it’s using POST for submitting form datas. I want to use GET. When i use GET instead of POST like this


<form action="/project/index.php?r=search/result" method="GET">

<div>

	<input type="text" name="search">

</div>

It’s sending form to this URL

http://domain.com/project/?search=test

instead of this :

http://domain.com/project/?r=search/result&search=test

It’s ignoring r=search querystring on action.

ADDITIONAL :

Yes i can put this to my form, to solve problem

<input type="hidden" name="r" value="search/result">

But what will happend if i change URL format with urlManager ? i mean i can change index.php?r=search/result to index.php/search/result . This time, that method won’t work.

So that anyone reading this will also know the solution; It is indeed to make the ‘r’ parameter a hidden field instead.

If you do that, and change the URL manager’s url format to ‘path’, you will (on form submission) end up with an URL like index.php/search/result?r=search/result&search=test , which will however work just fine. The downside is that you will have that extra r parameter in the URL which you might not like, but you can either only render the hidden field for ‘r’ when the URL manager’s path format is not ‘path’, or just leave it there so that you can easily switch between path and regular url format as you please.

In summary, make it a hidden field, like you suggested.