With great interest I have tried the Dependent Dropdown tutorial. Unfortunately I am stuck. The $_POST[‘Current-Controller’][‘country_id’] is always empty or not set. So I assumed that I typed a wrong controller name. It’s name is OrderController.php and the class’ name OrderController. So I tried the following variations always returning an empty or unset $_POST:
- $_POST[‘OrderController’][‘country_id’]
- $_POST[‘order’][‘country_id’]
- $_POST[‘Order’][‘country_id’]
- $_POST[‘country_id’]
Here is the states.php file which is my view file:
<div class="form" style="width:100%;">
<?php
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('order/dynamicstates'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city_id', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)
)
);
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city_id','', array());
?>
</div><!-- form -->
This is from the controller file, OrderController.php:
public function actionStates()
{
$this->render('states');
}
public function actionDynamicstates()
{
$data = array($_POST['Current-Controller']['country_id']=>'This is a Test');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
If I replace this line…
$data = array($_POST['Current-Controller']['country_id']=>'This is a Test');
…with the following line…
$data = array(1=>'This is a Test');
…then I get at least the ‘This is a Test’ displayed in the dropdown field.
So I am guessing that my $_POST is empty?! With firebug I get Error# 500 if I use the code as posted. If I use the 2nd line, where $_POST is not used there are no errors.
Do you have any idea what I am missing here?