Hello Yii forumers!
I am currently learning Yii/building a site and I have encountered a problem. I have a form that has 3 dropdown lists, depending on what you select in the first one, the next two are auto-populated, and this works fine. But when I go to submit my form to the database, the first dropDown value is shown as ‘NULL’ and I am not sure why. The first dropdown is CHTML dropdown, and the next is $form->dropDown, I think this might make a difference but I am not sure why because I thought I was still referencing the dropDown correctly and this would be picked up by the form. Can anyone tell me what I am doing wrong? Thank you very much!
Here is my first two drop downs, the third is the same as the second
<div class="row">
<?php echo CHtml::dropDownList('competition','', Competitions::model()->getAllCompetitions(),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('fixtures/Dynamiccompetitions'), //url to call
'update'=>'#'.CHtml::activeId($model, 'home_team').', #'.CHtml::activeId($model, 'away_team'),
)
)
); ?>
<div class="row">
<?php echo $form->labelEx($model,'home_team'); ?>
<?php echo $form->dropDownList($model,'home_team', array('empty'=>'--Select a Team--')); ?>
</div>
just in case you need to see my dynamiccompetitions!
public function actionDynamiccompetitions()
{
$id = $_REQUEST['competition'];
$data=Teams::model()->with('competitions')->findAll(array('condition'=>'competitions.id='.$id));
$data=CHtml::listData($data,'id','title');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}