I am tring to generate a code for dependent dropdownlist
I created successfully but when i try to save data i say city filed can not be blank
When i tried to resolve the problem useing fire bug
I seen that the city_id is coming without model name
<select id="city" name="city"> this is coming in fire bug
i think it should be Islands_city
If i do it manually code is work perfect
dropdown list code is echo CHtml ::dropDownList(‘city’, ‘’,$ldata, array(‘prompt’=>’–Select Skill Specialty–’));?>
If i do it as echo CHtml ::dropDownList($model,‘city’, ‘’,$ldata, array(‘prompt’=>’–Select Skill Specialty–’));?>
i got error Object of class Islands could not be converted to string
return str_replace(array(’[]’,’][’,’[’,’]’,’ ‘),array(’’,’’,’’,’’,’_’),$name);
Following is my _form.php
<?php echo $form->labelEx($model, ‘country’); ?>
<?php
$models = islands::model()->findAll();
$list = CHtml::listData($models,
'country', 'country');
echo CHtml::activeDropDownList($model, 'country', $list, array(
'ajax' => array(
‘type’=>‘POST’, //request type
‘url’=>CController::createUrl(‘islands/dynamiccities1’), //url to call.
//Style: CController::createUrl(‘currentController/methodToCall’)
//‘data’=>array(‘country’=>‘js:this.value’ ),
‘update’=>’#city’, //selector to update
//‘update’ =>’#’.CHtml::activeId($model,‘City’)
//‘data’=>array(‘country’=>‘js:this.value’ ),
//leave out the data key to pass all form values through
//‘data’ => array(‘category’, ‘js:this.value’),
))); ?>
<div id="nameerror"
class="errorMessage"></div>
<?php echo $form->error($model, 'country'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'city');
echo CHtml ::dropDownList('city', "", array(),array('prompt'=>'--Select Skill Specialty--'));
//echo CHtml ::dropDownList(model,'city', "", array(),array('prompt'=>'--Select Skill Specialty--'));
//echo $form->dropDownList($model,'city','',array(),array('prompt'=>'Select'));
?>
And following is my controller file
public function actionDynamiccities1()
{
$test=$_POST['Islands']['country'];
//echo $test;
$data=islands::model()->findAllbysql('select * from islands WHERE country=:country', array(':country'=>$test));
/*(‘ID=:ID’,
array(':ID'=> (int)$_POST['ID']));*/
$data=CHtml::listData($data,'ID','city');
foreach($data as $value=>$city)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($city),true);
}
}