Problem In Multiple Dependent Dropdown

hello everyboby i have state table with state_id and state, city table with city_id,city,state_id.While using the coding from websites hyiihelp.blogspot.in/2012/05/yii-dropdownlist-onchange.html, www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/ i dint get the output, any suggestion please.

Hi, give us your code (view and controller) and use the code snippet for that.

controller code

<?php

class PlaceController extends Controller

{

public &#036;layout='//layouts/column1';





public function filters()


{


	return array(


		'accessControl', // perform access control for CRUD operations


		'postOnly + delete', // we only allow deletion via POST request


	);


}





public function accessRules()


{


	return array(


		array('allow',  // allow all users to perform 'index' and 'view' actions


			'actions'=&gt;array('loadcities','index'),


			'users'=&gt;array('*'),


		)


	);


}





public function actionLoadcities()


{


   &#036;data=Place::model()-&gt;findAll('state_id=:state_id', array(':state_id'=&gt;(int) &#036;_POST['state_id']));


 


   &#036;data=CHtml::listData(&#036;data,'city_id','city');


 


   echo &quot;&lt;option value=''&gt;Select City&lt;/option&gt;&quot;;


   foreach(&#036;data as &#036;value=&gt;&#036;city)


   echo CHtml::tag('option', array('value'=&gt;&#036;value),CHtml::encode(&#036;city),true);


}





public function actionIndex()


{


	&#036;this-&gt;render('index');


}





public function loadModel(&#036;id)


{


	&#036;model=Place::model()-&gt;findByPk(&#036;id);


	if(&#036;model===null)


		throw new CHttpException(404,'The requested page does not exist.');


	return &#036;model;


}





/**


 * Performs the AJAX validation.


 * @param User &#036;model the model to be validated


 */


protected function performAjaxValidation(&#036;model)


{


	if(isset(&#036;_POST['ajax']) &amp;&amp; &#036;_POST['ajax']==='place-form')


	{


		echo CActiveForm::validate(&#036;model);


		Yii::app()-&gt;end();


	}


}

}

?>

model code

<?php

class Place extends CActiveRecord

{

public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}





/**


 * @return string the associated database table name


 */


public function tableName()


{


	return 'state';


}


public function rules()


{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


		array('state,state_id', 'required'),


		array('state,state_id', 'length', 'max'=&gt;20),


		// The following rule is used by search().


		// Please remove those attributes that should not be searched.


		array('state,state_id', 'safe', 'on'=&gt;'search'),


	);


}





/**


 * @return array relational rules.


 */


public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'state' =&gt; 'State',


		'state_id' =&gt; 'State Id'


	);


}





/**


 * Retrieves a list of models based on the current search/filter conditions.


 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


 */


public function search()


{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('state_id',&#036;this-&gt;state_id);


	&#036;criteria-&gt;compare('state',&#036;this-&gt;state,true);


	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}

}

?>

view Code

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'place-form',


'enableAjaxValidation'=&gt;false,

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;

<div class="row">

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'state_id'); ?&gt;


    &lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'state_id', 

array(1=>‘tamilnadu’,2=>‘karnataka’),

array(

'prompt'=&gt;'Select Region',


'ajax' =&gt; array(


'type'=&gt;'POST', 


'url'=&gt;CController::createUrl('loadcities'),


'update'=&gt;'#city', 

‘data’=>array(‘state_id’=>‘js:this.value’),

)));

echo CHtml::dropDownList(‘city’,’’, array(), array(‘prompt’=>‘Select City’)); ?>

    &lt;?php echo &#036;form-&gt;error(&#036;model,'state_id'); ?&gt;


&lt;/div&gt;





  


&lt;div class=&quot;row buttons&quot;&gt;


	&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div>

As you didn’t use snippet (<>) for your code, this is not very easy to follow.

You can try to debug it, check that the actionLoadcities is launch, then check if the controller return correct datas.

In PlaceController actionLoadcities() i got the error Undefined index: state_id

add




var_dump($_POST['state_id']));



at the beginning of the controller for debug