Hi
I had form content first name , last name .....etc . And tow drowpdownlist countries and cites , I loaded cites when Country drowpdownlist changed by ajax , and everything is cool . My problems :
1- when clicked submit and had error in validation , city value will replaced with empty value How To fix it ?
2- How to use $form-> with it I mean city drowpdownlist .
View :
Ajax Controller
Thanks in advance
I had form content first name , last name .....etc . And tow drowpdownlist countries and cites , I loaded cites when Country drowpdownlist changed by ajax , and everything is cool . My problems :
1- when clicked submit and had error in validation , city value will replaced with empty value How To fix it ?
2- How to use $form-> with it I mean city drowpdownlist .
- Form work if no error in validation
- Form after clicked on submit and return error in validation like username is empty ..etc
View :
<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>
Ajax Controller
public function actionDynamiccities() /// Called 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); }; }
Thanks in advance