How To Not Refrech The Search Filter?

Hello,

I was wondering if there is any way to solve this prob.

Every time i clic on add button it refreshes the page and I lose the inputed query in my search field. So, I have to do once again the search and it’s quite annoying (my search filter is quite big).

So, is there any solution to clic on add but without refresh the page or loosing the query ?

Thank you in advance

the view code for adding


<td style="width:10%;">

            <?php $imghtml=CHtml::image(Yii::app()->baseUrl.'/images/icon_add-doc.png', 'add.jpg', array(

                        //'htmlOptions'=>array(

                                "width" => 20,

                                "height" => 23,

                        //    )

                    ));

                        echo CHtml::link($imghtml, array('haves/create', 

                                'property_id'=>$data->Id, 

                                'brochure_id'=>$_GET['brochure_id'],

                                'TitleName'=>$_GET['TitleName'],

                                'PropUnitType'=>$_GET['PropUnitType'],

                                'PropLocation'=>$_GET['PropLocation'],

                                'ProjectType'=>$_GET['ProjectType'],

                                'MaxFinishedYear'=>$_GET['MaxFinishedYear'],

                                'MinFinishedYear'=>$_GET['MinFinishedYear'],

                                'MinRent'=>$_GET['MinRent'],

                                'MaxRent'=>$_GET['MaxRent'],

                                'BMinRent'=>$_GET['BMinRent'],

                                'BMaxRent'=>$_GET['BMaxRent'],

                                'Pet'=>$_GET['Pet'],

                                'Rented'=>$_GET['Rented'],

                            ));

                    ?>

        </td>

The controller code


public function actionCreate {

//# we can finde here the searching condition for the search filter


                $modelUnit = new PropUnit('search');

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

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

                    $modelUnit->attributes=$_GET['PropUnit'];

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

		{

			$model->property_id=$_GET['property_id'];

			if($model->save())

				$this->redirect(array('create',

                                    'brochure_id'=>$model->brochure_id,

                                    'TitleName'=>$_GET['TitleName'],

                                    'PropUnitType'=>$_GET['PropUnitType'],

                                    'PropLocation'=>$_GET['PropLocation'],

                                    'ProjectType'=>$_GET['ProjectType'],

                                    'MaxFinishedYear'=>$_GET['MaxFinishedYear'],

                                    'MinFinishedYear'=>$_GET['MinFinishedYear'],

                                    'MinRent'=>$_GET['MinRent'],

                                    'MaxRent'=>$_GET['MaxRent'],

                                    'BMinRent'=>$_GET['BMinRent'],

                                    'BMaxRent'=>$_GET['BMaxRent'],

                                    'Pet'=>$_GET['Pet'],

                                    'Rented'=>$_GET['Rented'],

                                    ));

		}

}

Could you be more specific. How are the search fields defined in your view file? Normally if you stick to GET variables for your search parameters, it should be easy to preload them onto your model and have that populate your search fields automatically between page refreshes

Thank you for the reply.

My search field are defined in another php file called (_propertysearch)and the adding fonction is in (_propertview) but they are in the same folder and using the same controller

for ex here is a peace of code foer the searching fonction


<div class="wide form">

<?php

       echo CHtml::beginForm(CHtml::normalizeUrl(array('haves/create')), 'get', array('id'=>'filter-form'))

            . '<div class="row" style="width:100%;">'

            . CHtml::encode('Project Name ')

            . CHtml::textField('TitleName', (isset($_GET['TitleName'])) ? $_GET['TitleName'] : '', array(

                'id'=>'TitleName',

                'style' => 'width:100%;'

                ))

            . '</div>'

............

             . '<div class="row">'

            . CHtml::submitButton('Search', array('name'=>''))

			. '</div>'           

			. CHtml::endForm();

                    ?>

  </div><!-- search-form -->

no one has an idea here ?

any help or suggestion would be much appreciated

thank you

You can try this

My link

thank you Rahif for your help, great extenssion

but I have one prob, after I input the searching inquery and when I hit the add button it remembers only one filter in my search form and the others disapear and I have to input them again

I am not sur why it’s happening, do you have an idea ?

thank you

Hi, I used in gridviews and It works fine.

Try with gridview filter of a simple model, and when you do it work, add the search form

Sorry but my english is very poor, luck.

in gridview it works fine no prob,

but in search form it remembers only one field and not the other

extension remember only $_GET parameters, be sure that your form have method = ‘get’.

I cant think anymore

http://www.yiiframework.com/wiki/324/cgridview-keep-state-of-page-and-sort/