Hi guys,
I’m developing a web application using yii. I have developed it in basic(default) theme. Everything works fine. But after adding a template, dependant dropdowns are not working. I mean after selecting a value in district, the respective taluks are not showing in second dropdown. Earlier it was working fine, but now its not working. Could somebody help me please…
Here is my code in view(_form.php) :
<div class="row">
<?php echo $form->labelEx($model,'district_id'); ?>
<?php echo $form->dropDownList($model, 'district_id', $model->getDistrict(), array(
'prompt' => 'Select district',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('taluqs'),
'update' => '#Inquiry_taluq_id',
)
)); ?>
<?php echo $form->error($model,'district_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'taluq_id'); ?>
<?php echo $form->dropDownList($model,'taluq_id',array(),array('empty'=>'Select taluk')); ?>
<?php echo $form->error($model,'taluq_id'); ?>
</div>
In my controller :
public function actionTaluqs() {
$taluqs = Taluq::model()->findAll('district_id=:district_id', array(':district_id' => (int) $_POST['Inquiry']['district_id']));
$return = CHtml::listData($taluqs, 'taluq_id', 'taluq_name');
foreach ($return as $taluqId => $taluqName) {
echo CHtml::tag('option', array('value' => $taluqId), CHtml::encode($taluqName), true);
}
}
In my model :
public function getDistrict()
{
//this function returns the list of categories to use in a dropdown
return CHtml::listData(District::model()->findAll(), 'district_id', 'district_name');
}
public function getTaluq()
{
//this function returns the list of categories to use in a dropdown
return CHtml::listData(Taluq::model()->findAll(), 'taluq_id', 'taluq_name');
}