Dropdownlist Depending On Another One

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 ?

I have not checked everything here but shouldn’t it be just


$id_struct = Yii::app()->request->getPost('id_structure');

instead of


$id_struct = $_POST['InfoComplementAAjouter']['id_structure'];

Perhaps, but the problem remains, although I adapt the code.

Ok, so what is the actual problem?

Surely, the action is not called if an option is selected.

Try


'url' => $this->createUrl(array('InfoComplementAAjouter/fillTypeList'))

for your ajax url option. If this doesn’t work please check for any errors in Firebug or similar tool on your browser.