Dependent dropdown data not coming

I have a dropdown list which takes data from "supercategorymaster" table to store in the "maintable" table.

When the value for this is selected I want another dropdown to be filled which will get data from "subcategorymaster" table which when filled up will save in "maintable" table.

The “subcategory” master table contains ‘supercategory_id’,‘supercategory_name’,‘supercategory_id’

In my register view:

<div class="row">

		<?php echo $form->labelEx($maintable,'supercategory'); ?>



		$supercategorydrop=CHtml::listData(SupercategoryMaster::model()->findAll(), 'supercategory_id', 'supercategory_name');

		echo $form->dropDownList($maintable,'supercategory', $supercategorydrop,



                                'ajax' => array(





		<?php echo $form->error($maintable,'religion'); ?>





	<div class="row">

		<?php echo $form->labelEx($maintable,'subcategory'); ?>


		   echo $form->dropDownList($maintable,'subcategory',array());


		<?php echo $form->error($maintable,'subcategory'); ?>




In the Controller for the subcategory(SubcategoryMaster) which picks up data from subcategory table

public function actionsubcategorycat()




             array(':parent_id'=>(int) $_POST['supercategory']));


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


                    echo CHtml::tag('option',




When I go to http://localhost/yiiitest/index.php?r=subcategorymaster/subcategorycat

I get following error

[b]PHP Error

Undefined index: supercategory[/b]

I have given access rules:



How can I get the data in teh second dropdown

Please use the code directive so that your code is more readable (<> on the editor toolbar)

For your error check the line where this error is reported I presume it’s this one:

<?php echo $form->labelEx($maintable,'supercategory'); ?>

This looks for the attribute $model->supercategory… and it seems you don’t have it .

Sorry About that

The error shows

PHP Error

Undefined index: supercategory






52 public function actionsubcategorycat()

53     {





58          $data=SubcategoryMaster::model()->findAll('parent_id=:parent_id',


60              array(':parent_id'=>(int) $_POST['supercategory ']));

That means that the post array does not have this value… could be that you did not declare that attribute as safe ?

I have checked and it is safe

Could it be because there is no supercategory in "subcategorymaste" table

"subcategorymaste" table only has


If this is the situation how can I solve it without changing the database

If you don’t have that filed you should have got the error "Property “<yourmodel>.supercategory” is not defined. "

Check again all your code… you need to use an existing attribute… be it a field name or declared in the model class…


I have a dependent dropdown containing religion and caste. The dropdown is working properly ie. when i select religion the caste corresponding to the religion are displayed, but only the religion information is stored in the database and the caste field is empty. The caste data is not stored in the database.


I have now been able to retrieve the data in the dependent dropdown, but I am getting a similar problem when saving the data.

Any Ideas?

Plz suggest some solution.


I have a dependent dropdown on the home page that is on views/site/index.php page it is not showing values when parent item is changed.

Is there some issue when placing a dependent dropdown on views/site/index.php