I am working on a search form which have a drop down menu filter. And the site is created by Yii.
My filter form looks like this before it's submitted: PIC 1
Form when I select the filters: PIC 2
But after I click the filter
button it comes again like this: PIC3
But I want the form should remain as PIC 2
after I submit the form when it shows the results.
My form is:
<div class="row">
<div style="float: left">
<label class="form_controller required">By Brand</label>
<select style="width: 148px;" id="select_options" name="SCDcustomer_contacts_cms[brand_select_option]">
<option value="none">Select an option</option>
<option value="brand_preference">Brand Preference</option>
<option value="brand_purchased">Brand Purchased</option>
</select>
</div>
<div id="select_a_brand" name="select_a_brand">
<?php echo $form->dropDownList($model,'brand_id', gGetBrandList('brand_id', 'brand_id, brand_name'), array('prompt'=>'Select a brand')); ?>
</div>
<script type="text/javascript">
$(document).ready(function(){
jQuery('#select_a_brand').hide();
$("#select_options").change(function(){
$( "select option:selected").each(function(){
if(($(this).attr("value")=="brand_preference") || ($(this).attr("value")=="brand_purchased") ){
$("#select_a_brand").show();
}
if($(this).attr("value")=="none"){
$("#select_a_brand").hide();
}
});
});
});
</script>
</div>
Rules function is:
public function rules()
{
return array(
array('scd_cust_id,cust_id,order_first_name,order_surname,order_email,order_postcode, brand_id, brand_select_option', 'safe', 'on'=>'search'),
);
}
Form filter is :
if(!empty($filter)) {
if ($this->brand_select_option == "brand_preference") {
$criteria->select .= ', COUNT(*) as brand_preference';
$criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
$criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';
$criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
$criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
$criteria->group = 't.contactid';
$criteria->order = 'COUNT(*) DESC';
$criteria->params = array(':brand_id'=>$this->brand_id);
$paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
}
if ($this->brand_select_option == "brand_purchased") {
$criteria->select .= ', SUM(product_price) AS brand_purchased';
$criteria->join .= ' INNER JOIN order_table ot ON ot.billing_contactid = t.contactid';
$criteria->join .= ' INNER JOIN order_item oi ON ot.scd_order_id = oi.scd_order_id';
$criteria->join .= ' INNER JOIN johnanthony_rstest.product p ON p.product_id = oi.product_id';
$criteria->condition .= (!empty($criteria->condition) ? ' AND ' : '') . 'p.brand_id=:brand_id';
$criteria->group = 't.contactid';
$criteria->order = 'SUM(product_price) DESC';
$criteria->params = array(':brand_id'=>$this->brand_id);
$paging['pagination']['route']='report/index?SCDcustomer_contacts_cms[brand_id]=' . $this->brand_id;//For ajax pagination URL
}
}
Ajax file is:
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_preference")) {
array_push($options['columns'], array(
'name'=>'brand_preference',
'filter'=>false,
'header'=>'Brand Preference (No of purchased items)',
'type'=>'raw',
'value'=>'$data->brand_preference',
));
}
if (!empty($model->brand_id) && ($model->brand_select_option == "brand_purchased")) {
array_push($options['columns'], array(
'name'=>'brand_purchased',
'filter'=>false,
'header'=>'Brand Purchased (Sum of purchased items)',
'type'=>'raw',
'value'=>'$data->brand_purchased',
));
}