title: Yii2: how to use custom validation function for activeform?
body: <p>In my form's model, I have a custom validation function for a field defined in this way</p>
  
  <pre><code>class SignupForm extends Model
  {
      public function rules()
      {
          return [
              ['birth_date', 'checkDateFormat'],
  
              // other rules
          ];
      }
  
      public function checkDateFormat($attribute, $params)
      {
          // no real check at the moment to be sure that the error is triggered
          $this-&gt;addError($attribute, Yii::t('user', 'You entered an invalid date format.'));
      }
  }
  </code></pre>
  
  <p>The error message doesn't appear under the field in the form view when I push the submit button, while other rules like the required email and password appear.</p>
  
  <p>I'm working on the Signup native form, so to be sure that it is not a filed problem, I've set the rule</p>
  
  <pre><code>['username', 'checkDateFormat']
  </code></pre>
  
  <p>and removed all the other rules related to the username field, but the message doesn't appear either for it.</p>
  
  <p>I've tried passing nothing as parameters to <code>checkDateFormat</code>, I've tried to explicitly pass the field's name to <code>addError()</code></p>
  
  <pre><code>$this-&gt;addError('username', '....');
  </code></pre>
  
  <p>but nothing appears.</p>
  
  <p>Which is the correct way to set a custom validation function? </p>