Form Field Values Not Saved In Database

Hello everybody,

I am trying to insert a new Comment into the Comment table with the Create Controller generated by gii.

Everything works except that the form field parent_id is being ignored.

I am filling out every field and every field is being saved in the database except the field parent_id.

The field parent_id is always saved as 0 although i entered other ids.

However, when I try to assign a value directly in the Controller with $model->parent_id = 1; it works.

So somehow the value from the form isn’t being transfered to $model->parent_id unlike all other fields.

Why is that so?

Any help is greatly appreciated

The parent_id have any other relationships? Do you enter the parent_id directly in the form?

may be in the database this field is a boolean/bool type .

and you 'd better also see the rules for this field in the Comment model .

<?php

class CommonMethods {

private &#036;data = array();





public function makeDropDown(&#036;parents)


{


    global &#036;data;


    &#036;data = array();


    foreach(&#036;parents as &#036;parent)


    {


       


            &#036;data[&#036;parent-&gt;hostel_information_id] = &#036;parent-&gt;hostel_name;


            &#036;this-&gt;subDropDown(&#036;parent-&gt;children);


           


    }


   


   return &#036;data;


}

public function subDropDown($children,$space = ‘—’)

{


    global &#036;data;


   


    foreach(&#036;children as &#036;child)


            {


               


                    &#036;data[&#036;child-&gt;hostel_information_id] = &#036;space.&#036;child-&gt;hostel_name;


                    &#036;this-&gt;subDropDown(&#036;child-&gt;children,&#036;space.'---');


            }


   


}

}

?>

make one file in component folder.

use following code in form file.

	&lt;?php &#036;parents = HostelInformation::model()-&gt;findAll('hostel_parent_id = 0');


 	  &#036;cm = new CommonMethods();


          &#036;data = &#036;cm-&gt;makeDropDown(&#036;parents);


          echo &#036;form-&gt;dropDownList(&#036;model,'hostel_parent_id',&#036;data,array('empty'=&gt;'--------Select------')); ?&gt;

above code is developed according to my requirement. you can change according to your requirement.