Model Validation Not Working

I have following action to handle register

 $model=new User('checkout');



            $model->attributes = $_POST['User'];

            //echo '<pre>';echo $model->username;die;


           echo  $model->getErrors(); die;



and model rules are

array('username', 'required', 'on' => 'checkout','message' => Yii::t('validation', 'Email can not be blank.')),

            array('username', 'unique', 'on' => 'checkout', 'message' => Yii::t('validation', 'Email has already been taken.')),


            array('username', 'unique'),

            array('passwordConfirm', 'required', 'on' => 'checkout','message' => Yii::t('validation', 'Confirm password can not be blank')),

            array('username', 'email', 'message' => Yii::t('validation', 'Invalid username/email format ')),

            //comapre passwords

Form post data is



    [fname] => hemc

    [lname] => k

    [username] => demo

    [dob] => 

    [password] => 

    [passwordConfirm] => 

    [agree] => 0


Problem -:there is no error while validating model.

Stack Overflow topic available here for anyone interested in the solution:

I believe the solution was to set scenario on the model before validation.