Ajax Dependent Drop Down

Hi everyone, I followed a wiki on how to make an ajax dependent drop down, I get the following error on firebug "NetworkError: 500 PHP Error - …/index.php/en/showroom/showcity"

My Index.php


echo CHtml::dropDownList('city_id','', array(1=>'London',2=>'Manchester',3=>'Liverpool'),

array(

'ajax' => array(

'type'=>'POST', //request type

'url'=>CController::createUrl('showroom/showcity'), //url to call.


'update'=>'#myID', //selector to update


))); 

 


echo CHtml::dropDownList('myID','', array());

On my controller


public function actionShowcity(){

	

    $data=Showroom::model()->findAll('Title=:Title', 

                  array(':Title'=>(String) $_POST['city_id']));

 

    

				   $data=CHtml::listData($data,'ID','Name');

    foreach($data as $value=>$name)

    {

        echo CHtml::tag('option',

                   array('value'=>$value),CHtml::encode($name),true);

				   

				   

    }

}

I’m guessing it’s my post request on $_POST[‘city_id’] , because if I change that to a string like “London” it works.

you’ve sent number instead string for city_id

your list array should be


array('London'=>'London','Manchester'=>'Manchester','Liverpool'=>'Liverpool')

instead


array(1=>'London',2=>'Manchester',3=>'Liverpool')

Thanks for the reply, unfortunately I’m still getting the same error

You should probably var_dump your $_POST and see what is inside.

Never mind guys, thanks for the replies. Somehow I forgot to include <?= CHtml::form(); ?>. I remember having the same issue a few months back. I need to learn my lesson.

@Reza m

Your reply was definitely useful as I would have been getting blank results otherwise.

Cheers