I am trying to create a dropdownlist in my view that basically pulls in the options from another model can you have a look to see what im doing wrong. the list is created but when i select and save i get no data inputed into the database and i get the error message field cannot be empty (it should do this if it’s empty).
Heres the code from my view.
<div class="row"> <?php echo $form->labelEx($model,'Broker_Id'); $models = BrokerDetails::model()->findAll(array('order' => 'Company_Name')); //This works fine pulling in the data from my BrokerDetails model $list = CHtml::listData($models, 'Broker_Id', 'Company_Name'); // This Also Works Fine when i display $list using print_r i can see the full array echo CHtml::dropDownList('Broker_Id',$brokers,$list); // This works to the point that it displays the correct drop down list but when i select an option and save it inputs nothing into the broker_id field of my client table in my database. echo $form->error($model,'Broker_Id'); ?> </div><!-- row -->
Bear in mind that i’m a total noob and i haven’t made any other changes elsewhere this is the only place i have created the code do i need to change my model or controller?
Anyways i hope you can help i have read all the tutorials and i have both of the books and i can’t do this simple thing.