Dependent Dropdown List Is Not Set In Updation Form

Hi friends,

I’m working with the drop down list and working fine while creation and deletion, but my problem is during the updating of that particular form…

I’m having pname(program name ) and cname(course name), when I’m clicking updating button the pname field loads automatically, but cname is not set and while submitting the form that field shows error and I need to re choose the pname field and cname field for every other field updating also it really create irritation for updating…

If any suggestion to keep that drop down field always set based on database values…

This is my code in view .

<?php echo $form->dropDownList($model,'pname',CHtml::listData(Programs::model()->findAll(

  array('order' => 'pname')),'pname', 'pname'),



    'prompt'=>'Choose your course',



      'url' => CController::createUrl('findcourses'),

      'data'=> array('pname'=>'js:this.value'),




		<?php echo $form->error($model,'pname'); ?>



	<div class="row">

		<?php echo $form->labelEx($model,'cname'); ?>

		<?php echo $form->dropDownList($model,'cname', array(),

               array('prompt'=>'Choose stream',




      'url' => CController::createUrl('findfees'),

      'data'=> array('cname'=>'js:this.value'),


               )); ?>


		<?php echo $form->error($model,'cname'); ?>


in controller

public function actionFindcourses()




     //$model=new Students;


		$model=new Students;


		$date=Yii::app()->dateFormatter->formatDateTime(time(), 'medium', false);

		$model->date= $date;

         $data = Courses::model()->findAll('pname=:pname',





        echo "<option value=''>Courses</option>";

        foreach($data as $value=>$name)

            echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);


In your view follow as below case for dependent dropdown for vertical & subvertical (check isset for second attribute and make query for getting data array from second dropdown if in update scenario), Its worked for me…


    <?php echo $form->labelEx($model, 'vertical_id'); ?>


    echo $form->dropDownList($model, 'vertical_id', CHtml::listData(Vertical::model()->findAll(array('order' => "`id` DESC")), 'id', 'name')

            , array(

            'prompt' => 'Select ',

            'ajax' => array(

            'type' => 'POST', //request type

            'url' => CController::createUrl('user/listSubVertical'), //url to call.

            'update' => '#User_sub_vertical_id', //selector to update

            'data' => array('vertical_id' => 'js:this.value'),



    <?php echo $form->error($model, 'vertical_id'); ?>



    <?php echo $form->labelEx($model, 'Sub vertical'); ?>


    if ($model->sub_vertical_id) {

        $criteria = new CDbCriteria;

        $criteria->addCondition('vertical_id =' . $model->vertical_id);

        $dataArr = CHtml::listData(SubVertical::model()->findAll($criteria, array('order' => "`id` DESC")), 'id', 'name');

        echo $form->dropDownList($model, 'sub_vertical_id', $dataArr, array('prompt' => 'Select'));

    } else {

        echo $form->dropDownList($model, 'sub_vertical_id', array(), array('prompt' => 'Select'));



    <?php echo $form->error($model, 'sub_vertical_id'); ?>