Dropdown storing different value

Hi im newbie here, i have a problem with my dropdown, I hope you can help me :)

I have a dropdown that displays ‘institution names’ which is taken from other table, instead of storing ‘institution names’ i want to store its ‘institution_id’.

I already made a dropdown list that displays institution names and it stores the institution name instead of institution id, that’s why when i click create it’s always displaying a warning saying ‘institution cannot be blank’

heres the code _form:


    <td><?php echo $form->labelEx($model,'Institution'); ?></td>

    <td><?php echo $form->dropDownList($model,'InstitutionShortname',

        CHtml::listData(Institution::model()->findAll(), 'institution_shortname', 'institution_shortname')); ?></td>


I really have to display the institution names in a dropdown. I dont know what to do please help me.

Hi yiigirl. i would be very glad to help you as much as i can. can you be more specific with the details like including the tables of your database? just a suggestion though :D

heres my 2 tables








im working in deductions table

I already have a dropdown that displays values(which is institution_shortname) from another table

my prob is that how can I store the equivalent ‘institution_ref_id’ of the chosen ‘institution_shortname’ from dropdown list in the ‘ps_ref_deduction_table’

hope you can help thanks :)

Hi yiigirl and welcome.

Here is an example

<?php echo $form->dropDownList($model, 'attributeId', CHtml::listData(ModelB::model()->findAll(), 'attributeId', 'otherAttribute')); ?>

you can do it this way


&lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'Institution'); ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'InstitutionShortname',

    CHtml::listData(Institution::model()-&gt;findAll(), '[b]institution_ref_id[/b]', 'institution_shortname')); ?&gt;&lt;/td&gt;



CHtml::listData(Institution::model()->findAll(), 'institution_ref_id', 'institution_shortname'));

I dont know that it was as easy as that! thank you very much :D