Using Compareattribute

Hello, I’m new to Yii.

I added an extra text field to the __form view named passCompare. This will make user typing the password twice.

I tried this in model and it’s not working:


 array('passCompare', 'compare', 'compareAttribute' => 'pass','on'=>'insert'),

The model:


<?php


class User extends CActiveRecord {


    public $passCompare; //campul pentru compararea parolei (Confirmare parola)


  ...........


    public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

            .............

            array('pass', 'length', 'max' => 64),

            array('pass', 'match', 'pattern' => '/^[a-z0-9_-]{6,20}$/i'),

            array('passCompare', 'compare', 'compareAttribute' => 'pass','on'=>'insert'),

            ............

        );

    }


  ................................


}

The view:




<div class="form">


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

	'id'=>'user-form',

	'enableAjaxValidation'=>true,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'username'); ?>

		<?php echo $form->textField($model,'username',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'username'); ?>

	</div>

........................

	<div class="row">

		<?php echo $form->labelEx($model,'pass'); ?>

		<?php echo $form->passwordField($model,'pass',array('size'=>60,'maxlength'=>64)); ?>

		<?php echo $form->error($model,'pass'); ?>

	</div>

        

        <div class="row">

            <?php echo $form->labelEx($model,'passCompare');?>

            <?php echo $form->passwordField($model,'passCompare',array('size'=>60,'maxlength'=>64));?>

            <?php echo $form->error($model,'passCompare'); ?>

        </div>

........................


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


</div><!-- form -->



When I’m going to the route yii/index.php/user/create strange things happens. Like it inserts data in the database and giving form errors ‘username already exists’. It’s like inserting a user twice, but clicking on ‘create’ button only once(in a clean table).