Yii Ajaxform Validation Only Validates A Part Of The Form

I got a Yii form which collects data for three models. I am using ajaxvalidation, on change and on submit:


<?php $form=$this->beginWidget('CActiveForm', array(

    'id'=>'offer-form',

    'enableAjaxValidation'=>true,

    'enableClientValidation'=>true,

    'clientOptions' => array(

        'validateOnChange'=>true,

        'validateOnSubmit'=>true,

    )   

)); ?>

Now the problem is that that only the first three inputs are getting validated, code of these inputs:

1:


<div class="input-bg wide-input">


                    <?php 

                    //fill this field after selecting newspaper

                    echo $form->hiddenField($newspaper, 'id'); ?>

                    <?php echo $form->textField($newspaper, 'name', array('maxlength' => 45, 'placeholder'=>'Krantnaam')); ?>

                    <?php echo $form->error($newspaper, 'name', array('class'=>'error')); ?>

                </div>

                <a class="button gray-button">Aanbieden</a>

2 and 3:


<div class="input-bg linked-input">

                    <?php echo $form->textField($address, 'postalcode', array('maxlength' => 45, 'placeholder'=>'Postcode')) ?>

                    <?php echo $form->error($address, 'postalcode'); ?>

                </div>


                <div class="input-bg linked-input">

                    <?php echo $form->textField($address, 'street_number', array('maxlength' => 45, 'placeholder'=>'Huisnummer')); ?>

                    <?php echo $form->error($address, 'street_number'); ?>

                </div>

Those three inputs serve for two models which are $newspaper and $address. Now the case is that those three inputs are perfectly validated(on change and on submit) where the other seven inputs are not validated, example of one of those inputs that are not validated:


<div class="input-bg linked-input">

            <?php echo $form->textField($offer, 'firstname', array('maxlength' => 45, 'placeholder'=>'Voornaam')); ?>

            <?php echo $form->error($offer, 'firstname'); ?>

        </div>

Finally, I will post my controller code:


$this->performAjaxValidation($offer, 'offer-form');

$this->performAjaxValidation($address, 'offer-form');

$this->performAjaxValidation($newspaper, 'offer-form');


if(Yii::app()->getRequest()->getIsAjaxRequest()) {

    echo CActiveForm::validate( array($address));  

    echo CActiveForm::validate( array($offer));

    echo CActiveForm::validate( array($newspaper)); 

    print_r($_POST);

    die();

    //Yii::app()->end(); 

}

If I am submitting or changing the form I do get back JSON with the errors for the fields that are not validated on the eye, but they don’t get an error state.

I hope there is someone that can see a mistake or anything else.

Greetz,

Dear Friend

Kindly change the controller logic.




$offer=new Offer;

$newspaper=new Newspaper;

$address=new Address;

if(isset($_POST['ajax']) && $_POST['ajax']==='offer-form')

{

	echo CActiveForm::validate(array($newspaper,$address,$offer));

	Yii::app()->end();


}

//followed by other things.



Regards.

Thanks, this did the job.