我有表单内容名字,姓氏......等等。并拖拽下拉列表国家和城市,当国家下拉列表被ajax更改时,我加载了城市,一切都很酷。我的问题:
1-点击提交时验证出错,城市值将替换为空值如何解决?
2- 如何使用 $form-> 我的意思是 city droppdownlist 。
如果验证没有错误,则表单工作
单击提交后的表单并在验证中返回错误,例如用户名为空..等
看法:
<div class="row">
<?php echo $form->labelEx($model,'البلد'); ?>
<?php
/*
echo chtml::activeDropDownList($model,'country',$model->getcountry(),array('prompt'=>'اختر بلدك ') ,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('current/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
))
);
*/
echo CHtml::activedropDownList($model,'country',$model->getcountry(),
array(
'prompt'=>'اختر البلد أو المنطقة ',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('register/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
))
);
///
////
?>
<?php echo $form->error($model,'country'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'المدينة'); ?>
<?php
echo CHtml::dropDownList('city','', array());
?>
<?php echo $form->error($model,'city'); ?>
</div>
城市负荷控制器:
public function actionDynamiccities() /// Call Ajax
{
$country=intval($_POST['Users']['country']);
$data=Cities::model()->findAll('country_id=:country_id',
array(':country_id'=>$country));
$data=CHtml::listData($data,'id','city_name_e');
echo CHtml::tag('option',
array('value'=>''),CHtml::encode('Select Your City '),true);
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
};
}