hemc4
hemc4

Reputation: 1633

Model Validation Not Working

I have following action to handle register

 $model=new User('checkout');
        if(!empty($_POST['User'])){

            $model->attributes = $_POST['User'];
            //echo '<pre>';echo $model->username;die;
            $model->validate();
           echo  $model->getErrors(); die;
        }
        $this->render('register',array('model'=>$model));

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

Array
(
    [fname] => hemc
    [lname] => k
    [username] => demo
    [dob] => 
    [password] => 
    [passwordConfirm] => 
    [agree] => 0
)

Problem -:There is no error while validating model.

Upvotes: 0

Views: 304

Answers (1)

soju
soju

Reputation: 25322

getErrors will return an array, you should try this :

var_dump($model->getErrors());

or

print_r($model->getErrors());

PS : you should display errors in your CActiveForm with errorSummary

Upvotes: 2

Related Questions