Yii Framework Forum: Updating Problem With Dropdownlist - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Updating Problem With Dropdownlist Rate Topic: -----

#1 User is offline   sanat 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-September 12
  • Location:Caracas, Venezuela

Posted 17 February 2013 - 05:34 PM

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'); ?>
</div>

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 ?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 17 February 2013 - 08:01 PM

Hi sanat,

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

#3 User is offline   sanat 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-September 12
  • Location:Caracas, Venezuela

Posted 17 February 2013 - 08:14 PM

View Postsoftark, on 17 February 2013 - 08:01 PM, said:

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)
{
$model=$this->loadModel($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]
{
$model->attributes=$_POST['Naturales'];
if($model->save()) {
$this->_deudores = $model->deudor; // Updating the child
$this->_deudores->attributes=$_POST['Naturales'];
$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()) {
                                                                        $this->redirect(array('view','id'=>$model->id_natural));
} else {
 throw new CHttpException(404, 'No se pudo ACTUALIZAR los Datos en el Archivo DEUDORES!');          
}
}
}
$this->render('update',array('model'=>$model,
));
}

0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 17 February 2013 - 08:33 PM

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?
0

#5 User is offline   sanat 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-September 12
  • Location:Caracas, Venezuela

Posted 17 February 2013 - 09:25 PM

View Postsoftark, on 17 February 2013 - 08:33 PM, said:

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.
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 17 February 2013 - 10:37 PM

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

#7 User is offline   sanat 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-September 12
  • Location:Caracas, Venezuela

Posted 18 February 2013 - 06:00 PM

View Postsoftark, on 17 February 2013 - 10:37 PM, said:

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users