Post method won't work in advanced search

I changed


'method'=>'get'

to


'method'=>'POST'

in category _search page. when i go to the category/admin, advanced search and search category, i see searched item in url and i see GET instead of POST method in firebug. why?

You will find something like the following in your admin view file:




Yii::app()->clientScript->registerScript('search', "

...

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('xxx-grid', {

		data: $(this).serialize()

	});

	return false;

});

");



This is it.

The "advanced search" functionality of gii-generated admin page uses a javascript function "$.fn.yiiGridView.update()" to update the grid by an ajax call. This javascript function is an inportant part of CGridView, and it uses "GET" method.

thank you,

is this possible to use "POST" method?

Well, I think it should be possible, but I don’t know if it is easy or not.

I never tried it because I didn’t need to.

For what reason do you want to use "POST" method?

if i use ajax, some gridview complex column can’t load correctly -i think problem is with jquery conflict -

and if i use get i see a long get request in url like ‘/category[title]/category[option]/…/…’ and sometimes i get apache error for long get request.

i like ajax solution but it doesn’t work, unless i remove complex gridview column.

I see.

  1. Delete the submit event handler, then your search form will be submitted using "POST" method.



Yii::app()->clientScript->registerScript('search', "

...

//$('.search-form form').submit(function(){

//        $.fn.yiiGridView.update('xxx-grid', {

//                data: $(this).serialize()

//        });

//        return false;

//});

");



  1. Modify the actionAdmin() method in your controller to handle not only $_GET but also $_POST to receive the input from the form:



	public function actionAdmin()

	{

		$model = new YourModel('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['YourModel']))

			$model->attributes=$_GET['YourModel'];

		else if(isset($_POST['YourModel']))

			$model->attributes=$_POST['YourModel'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}



Then, I hope the search will work … by normal page refresh, not by ajax.

I have not tested it, and it may have some problem …

thank u softark.

it works perfectly for me.