I have two dropDownLists in my view. One’s content depending on the value of the other. I’ve looked for how to do it, but what I found didn’t work for me. Below my view and the action in the controller :
<div class="row">
<?php echo $form->labelEx($model,'id_structure'); ?>
<?php echo $form->dropDownList($model, 'id_structure',
GxHtml::listDataEx(StructureInformation::model()->findAllAttributes(null, true)),
array('ajax' => array('type' => 'POST',
'url' => CController::createUrl('InfoComplementAAjouter/fillTypeList'),
'update' => '#typeDonnee',
'data' => array('id_structure' => 'js:this.value'))
)); ?>
<?php echo $form->error($model,'id_structure'); ?>
</div><!-- row -->
<div class="row">
<?php echo $form->labelEx($model,'type'); ?>
<?php echo $form->dropDownList($model, 'type', array(), array('prompt' => 'Sélectionner', 'id'=>'typeDonnee')) ?>
<?php echo $form->error($model,'type'); ?>
</div><!-- row -->
<div class="row">
The action looks like this :
public function actionFillTypeList(){
$id_struct = $_POST['InfoComplementAAjouter']['id_structure'];
$taille = StructureInformation::model()->find('id = ' . (int)$id_struct)->taille;
$un = array('text'=> 'Texte', 'radio' => 'Bouton radio', 'dropDownList' => 'Liste déroulante');
$plusieurs = array( 'checkboxlist' => 'Choix multiple',);
if($taille == 1){
foreach ($un AS $value => $name){
$opt = array();
$opt['value'] = $value;
echo CHtml::tag('option', $opt, CHtml::encode($name), true);
}
}
if($taille > 1){
foreach ($plusieurs AS $value => $name){
$opt = array();
$opt['value'] = $value;
echo CHtml::tag('option', $opt, CHtml::encode($name), true);
}
}
die;
}
How can I fix the problem ?