Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Load Data By Ajax Disappeared When Valdiation Return Erorr

$
0
0
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 .

  • Form work if no error in validation Posted Image
  • Form after clicked on submit and return error in validation like username is empty ..etc Posted Image

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

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>