Piyush
Piyush

Reputation: 4007

compare two fields in yii2

I want to compare and return error message if they are equal.

trying like this but not working

[['HRMS_candidateAlternateEmail'], '!compare', 'compareAttribute' => 'HRMS_candidateEmail'],

what will be write way.

Upvotes: 1

Views: 867

Answers (2)

Criesto
Criesto

Reputation: 1991

Change !compare to compare:

[['HRMS_candidateAlternateEmail'], 'compare', 'compareAttribute' => 'HRMS_candidateEmail', 'operator'=>'!='],

More info here and here. Hope that helps.

Upvotes: 1

Piyush
Piyush

Reputation: 4007

I found it just added 'operator'=>'!=' and it works.

 [['HRMS_candidateAlternateEmail'], 'compare', 'compareAttribute' => 'HRMS_candidateEmail','operator'=>'!='],

Upvotes: 0

Related Questions