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'); ?>
<?php
$supercategorydrop=CHtml::listData(SupercategoryMaster::model()->findAll(), 'supercategory_id', 'supercategory_name');
echo $form->dropDownList($maintable,'supercategory', $supercategorydrop,
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('subcategorymaster/subcategorycat'),
'update'=>'#subcategory')));
?>
<?php echo $form->error($maintable,'religion'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($maintable,'subcategory'); ?>
<?php
echo $form->dropDownList($maintable,'subcategory',array());
?>
<?php echo $form->error($maintable,'subcategory'); ?>
</div>
In the Controller for the subcategory(SubcategoryMaster) which picks up data from subcategory table
public function actionsubcategorycat()
{
$data=SubcategoryMaster::model()->findAll('parent_id=:parent_id',
array(':parent_id'=>(int) $_POST['supercategory']));
$data=CHtml::listData($data,'supercategory_id','supercategory_name');
foreach($data as $value=>$subcategory)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($subcategory),true);
}
}
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:
[b]‘actions’=>array(‘index’,‘view’,‘castecat’),
'users'=>array('*'),[/b]
How can I get the data in teh second dropdown