Updating Problem With Dropdownlist

Hi Community,

I have a dropDownList in my form which assign the value correctly when I create the record but doesn’t work in the update. The form creates a data form a Person and the attributte is ‘sexo’. Here is the code:

In the _form:

<div class="row">

	<?php echo $form->labelEx($model,'sexo'); ?>

	 <?php echo $form->dropDownList($model,'sexo',$model->ValorSexo); ?>

	<?php echo $form->error($model,'sexo'); ?>


In the model:

    const SEX_M="M";

    const SEX_F="F";

public function rules()



       array('sexo', 'in','range' => self::getRangoSexo()),


    public function getRangoSexo()


        return array( self::SEX_M, self::SEX_F );



    public function getValorSexo()


        return array(

                     self::SEX_F => 'Femenino',

                     self::SEX_M => 'Masculino',                                



For example, when I am updating the record has the value “F”, I click in the combo the word “Masculino” I it doesn’t update to the letter ‘M’. I debuged the code and find that $_POST[‘Naturales’] is unsset, so the action update in the controller does nothing. ‘Naturales’ is the model’s name.

What am I doing wrong ? Any help will be appreciated ?

Hi sanat,

I see nothing wrong so far. So the problem may be in the controller code for updating. Could you post it?

Thanks softark, here is the method Update of the controller, you will see I am updating to records at the same time, it works in the method Create.

public function actionUpdate($id)



// Uncomment the following line if AJAX validation is needed

// $this->performAjaxValidation($model);

if(isset($_POST['Naturales']))// [b]When I debuged the program, $_POST['Naturales'] is unset, I don't know why, because I clicked in the dropDownList[/b]



if($model->save()) {

$this->_deudores = $model->deudor; // Updating the child


$this->_deudores->attributes=array( 'id_ced_rif' =>   $model->id_ced_rif,                                                                                                                   'id_no_rif' => $model->no_ced_rif,

                                                                                                                        'nombre_persona' => $model->nombre_persona,


if( $this->_deudores->save()) {


} else {

 throw new CHttpException(404, 'No se pudo ACTUALIZAR los Datos en el Archivo DEUDORES!');          







Hmm, I see nothing wrong again.

Just for double checking, is your current model ‘Naturales’?

If it were ‘Person’, then you should receive the input by $_POST[‘Person’].

Could you check the $_POST?

Naturales is the model. I don’t know why the $_POST[‘Naturales’] is unset, that’s why the action (method) doesn’t update the data, but if I change a value in any of the textboxes of the form, the $_POST[‘Naturales’] is set and the action perfoms the update of the data, but if I only click the dropdownlist then nothing change.

Well, then I would like to see your view code for updating.

Many thanks Softark for your answers, but I’d solved the problem. I wrote a code in the AfterValidation Method, and it was wrong, it affects the value of the dropdownlist and make it a constant value, so when I clicked the dropdownlist it assign the new value correctly, therefore, in the AfterValidation, it changed to a constant value, that’s why assume that the problem was in the dropdownlist.

I’d rewrote the code again, in the aftervalidation method, and it works perfectly.

In conclusion, the problem were in the aftervalidation method, the dropdownlist works correctly.

Thnaks again.