Hello everyone… I need some experienced help. The history is:
Exist a form into a page for discriminate about registers in the DB. The form has two dropdownlist dependent, a master and a slave, users types and categories from the users types. When the form is complete, and submit, the same page is render again, showing the results in a GridView. The problem here is about the data from the dropdownlist, the two of them. When the page is render again, needs show the previous data selected, the user have to know what search… I can’t doit.
The master/slave are configure with ajax, it works fine! Here is the source…
View Form:
(!empty($_GET['tipo_usuario']))? $tu=$_GET['tipo_usuario'] : $tu=null; //To get the selected data
echo CHtml::dropDownList('tipo_usuario',$tu, array([cliente] => 'Usuario de Internet', [proveedor_privado] => 'Proveedor Sector Comercial', [proveedor_publico] => 'Proveedor Sector Público y Social'),
array(
'empty'=>'Tipo de usuario...',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('adminPanel/dynamicList'),
'update'=>'#categoria',
'data'=>array('tipo_usuario'=>'js:this.value'),
),
'style'=>'width:30%',
));
(!empty($_GET['categoria']))? $cat=$_GET['categoria'] : $cat=array();
echo CHtml::dropDownList('categoria',$cat,array(),array('empty' => 'Categoria...', 'style'=>'width:30%', 'disabled'=>false));
Controller, actionDynamicList function:
public function actionDynamicList()
{
if(Yii::app()->request->isAjaxRequest)
{
echo CHtml::tag('option',array('value'=>''),CHtml::encode('Categoria...'),true);
if($_POST['tipo_usuario']=='proveedor_privado')
{
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 1'), true);
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 2'), true);
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 3'), true);
}else if($_POST['tipo_usuario']=='proveedor_publico'])
{
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 4'), true);
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 5'), true);
echo CHtml::tag('option', array('value'=>1), CHtml::encode('Cat 6'), true);
}
}
}
Could anyone helps me?