How To Customize Form Validate Field ?

[b]Hi All

I Created form by Form Generator but I need to use one field in forgetpassword view ,

My problem : Validation message show for all fields , I need to show Validation message just

For one field , " Email field " With out Create new model because i used it for another views.

How I To do that ?[/b]

thanks in Advance

for this you have to use Scenario.

you can get better idea from yii guide and This Link

Thank you kiran , But how I can use it without Scenario model ??? it’s possible ? .

this is my Code I hope will help u to help me :) .


/* @var $this UsersController */

/* @var $model Users */

/* @var $form CActiveForm */


<div class="form">

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



)); ?>

	<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,'email'); ?>

		<?php echo $form->textField($model,'email'); ?>

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


	<div class="row buttons">

		<?php echo CHtml::submitButton('Submit'); ?>


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

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

Users Model :



 * This is the model class for table "tbl_users".


 * The followings are the available columns in table 'tbl_users':

 * @property integer $user_id

 * @property string $en_username

 * @property string $ar_username

 * @property string $email

 * @property string $password

 * @property string $password_key

 * @property integer $status

 * @property string $en_signature

 * @property string $ar_signature

 * @property string $register_date

 * @property string $key


 * The followings are the available model relations:

 * @property Articles[] $articles

 * @property Articles[] $articles1

 * @property Supervisor[] $supervisors

 * @property Topstory[] $topstories



class Users extends CActiveRecord



	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Users the static model class




     //// Add new filed 

     public $passwordconfirm;


     public $emailconfirm;

     public $status;


/// End add new filed 

	public static function model($className=__CLASS__)


		return parent::model($className);



	 * @return string the associated database table name


	public function tableName()


		return 'tbl_users';



	 * @return array validation rules for model attributes.


	public function rules()




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

		// will receive user inputs.

		return array(

			array('en_username,email', 'required'),

			array('status', 'numerical', 'integerOnly'=>true),

			array('en_username, ar_username, email, password, password_key, key', 'length', 'max'=>255),

			array('en_signature, ar_signature', 'length', 'max'=>400),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('user_id, en_username, ar_username, email, password, password_key, status, en_signature, ar_signature, register_date, key', 'safe', 'on'=>'search'),



             array('password, passwordconfirm', 'required', 'on'=>'insert'),

            array('password, passwordconfirm', 'length', 'min'=>6, 'max'=>40),

            array('password', 'compare', 'compareAttribute'=>'passwordconfirm'),


             array('email,emailconfirm','required', 'on'=>'insert'),

            array('email, emailconfirm', 'email'),

            array('email', 'compare', 'compareAttribute'=>'emailconfirm'),








	 * @return array relational rules.


	public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'articles' => array(self::HAS_MANY, 'Articles', 'user_id'),

			'articles1' => array(self::HAS_MANY, 'Articles', 'editby'),

			'supervisors' => array(self::HAS_MANY, 'Supervisor', 'user_id'),

			'topstories' => array(self::HAS_MANY, 'Topstory', 'user_id'),




	 * @return array customized attribute labels (name=>label)


	public function attributeLabels()


		return array(

			'user_id' => 'User',

			'en_username' => 'En Username',

			'ar_username' => 'Ar Username',

			'email' => 'Email',

			'password' => 'Password',

			'password_key' => 'Password Key',

			'status' => 'Status',

			'en_signature' => 'En Signature',

			'ar_signature' => 'Ar Signature',

			'register_date' => 'Register Date',

			'key' => 'Key',




	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


	public function search()


		// Warning: Please modify the following code to remove attributes that

		// should not be searched.

		$criteria=new CDbCriteria;












		return new CActiveDataProvider($this, array(











thanks in advance .

you want to use without scenario… so, i thnk its not possible or i haven’t use if possible.

I found you already use scenario in model as,

array('password, passwordconfirm', 'required', 'on'=>'insert'),

So, use same thing for the current scenario as only email will required field for particular scenario and call that model in controller passing particular scenario…

Syntex is as wiki link provided in previous comment.