Listbox + Listdata In Form, Display Text But Send Id

Hi everybody,

I have a table with foreign key toward another table in order to have a relation one-to-many.

In the form of the first table, I put a listBox where I display each name corresponding with all ids available in the second table. Thus, the user who creates his new record can select any object of the second table he wants in the list. >

Problem starts here, I display in my listbox the names corresponding of the ids, however this columns is waiting for integer (so the ids) and not text. So the selection is text, but I need to send to the database the ids matching with the selection. And I don’t really know how to do it.

Well, I have an idea to remove the rule like what the selection need to be integer, then add beforesave function where I’ll transform all the text selected by the ids corresponding to it. However I don’t know if it’s a good method. Do you have any idea ??

here is how I display my listbow :


echo Chtml::activeListBox($model,'A_names',Chtml::listData(my_user::model()->findAll(),'B_id','name'),array('multiple'=>'multiple'));

Thanks

you should use CHtml::listData() to build the list data for listbox




$table2Models=Table2::model()->findAll();

$table2List=CHtml::listData($table2Models,'id','name');


echo CHtml::activeListBox($model,'attribute',$table2List);



huuun, yep that’s what I’ve done