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

Ajax Validation Is Not Performed For Second Model

$
0
0
I have created a form using two models name customer and shippingaddress, now the ajax validation is working for the first model elements, and for the second model.

This is the form code

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'customer-form',
	'enableAjaxValidation'=>true,
)); ?>    
    
    <div class="requid">Required Field <span style="color:#d32c3b;">*</span></div>

	<?php echo $form->errorSummary(array($model,$model2));?>
<div class="noncolor bor" style="margin-top:2%">         
    
    <?php if(Yii::app()->user->hasFlash('error4')): ?>
 
		<div class="flash-success">
			<?php echo Yii::app()->user->getFlash('error4'); ?>
		</div>
		<?php endif; ?>
    <table class="tbl_fieldset" >
	<tbody>
	<tr><td></td></tr>
		<tr style="display:none" >
			<th class="name">Date Added</th>
			<td >
		<?php  if($model['date_added']==''){echo $form->textField($model,'date_added',array('size'=>30,'value'=>$date));}
		else{echo $form->textField($model,'date_added');}
		?>
		<?php echo $form->error($model,'date_added'); ?></td>
			<td> </td>
		</tr>
		<tr >
			<th class="name" >First Name <span style="color:#d32c3b;">*</span></th>
			<td >
			<?php echo $form->textField($model,'firstname',array('size'=>35,'maxlength'=>50)); ?>           
            <?php echo $form->error($model,'firstname'); ?></td>
			<td> </td>
		</tr>	
        <tr >
			<th class="name" >Shipping Name<span style="color:#d32c3b;">*</span></th>
			<td >
			<?php echo $form->textField($model2,'name',array('size'=>35,'maxlength'=>50)); ?>           
            <?php echo $form->error($model2,'name'); ?></td>
			<td> </td>
		</tr>
        
        <tr >
			<th class="name" >Shipping Country <span style="color:#d32c3b;">*</span></th>
			<td >		
			<?php   					
            echo $form->dropDownList($model2,'country_id',CHtml::listData(Country::model()->findAll(), 'country_id', 'country_name','');
                         ?>        
		<?php echo $form->error($model2,'country_id'); ?></td>
			<td> </td>
		</tr>
		<tr> 	
        <td> </td>	
		<td ><?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class' => 'sub', 'onclick'=> 'assign_state_city()',)); ?>  <td></tr>
	</tbody>
</table>      
    
</div>
    

<?php $this->endWidget(); ?>




The validation rules are defined for two models in their respective models.

The controller code:

for ajaxvalidation

			
	$this->performAjaxValidation($model,$model2);
        
	protected function performAjaxValidation($model,$model2)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='customer-form')
		{
			echo CActiveForm::validate($model,$model2);
			Yii::app()->end();
		}
	}


The ajax validation is only working for the first model only..
Need some help..

Viewing all articles
Browse latest Browse all 18717

Trending Articles



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