radioButtonList and dropDownList value stored as null in mysql

I’m new to yii. I have this problem where my data stored in radiobuttonlist or dropDownList is not saved in the database. It always store as null in mysql. here’s my code

View:

<?php

$form = $this->beginWidget(‘CActiveForm’);

echo $form->label($model,‘gender’);

echo $form->radioButtonList($model,‘gender’,array(‘M’=>‘Male’,‘F’=>‘Female’));

echo $form->label($model,‘cat’);

echo $form->dropDownList($model,‘cat’,$category);

echo CHtml::submitButton(‘Submit’);

$this->endWidget();

?>

Controller:

public function actionCreate()

{


    &#036;model=new Test;


    if(isset(&#036;_POST['Test']))


    {


                    &#036;model-&gt;attributes=&#036;_POST['Test'];


                    if(&#036;model-&gt;save()){


            &#036;this-&gt;redirect(array('index'));


                    }


                    else


                        var_dump(&#036;model-&gt;errors);


    }


            &#036;cat = array('st'=&gt;'STAFF','ot'=&gt;'OTHERS');


            &#036;model-&gt;gender='M';


    &#036;this-&gt;render('create',array(


        'model'=&gt;&#036;model,'category'=&gt;&#036;cat


    ));


}

Kindly help… Thanks in advance

Hi,

How is your data model defined (in protected/models/yourmodel.php:

  • is "gender" declared as varchar (because of "M" or "F" options) or as boolean ? In that last case you will have to do some data manipulation

  • same for your "cat" field

  • what are the defaults settings fror "gender" and "cat" fields in your database structure ?

  • double check your rules …