title: Invalid validation rule: a rule must specify both attribute names and validator type, in Yii2
body: <p>In my basic app project, I'm trying to integrate the signup form, I'm getting this error:</p>
  
  <blockquote>
    <p>Invalid validation rule: a rule must specify both attribute names and validator type.</p>
  </blockquote>
  
  <p>My code is here.</p>
  
  <p><strong>SignUpForm.php</strong></p>
  
  <pre><code>&lt;?php
  namespace app\models;
  use yii\base\Model;
  use app\models\User;
  
  /**
   * Signup form
   */
  class SignupForm extends Model
  {
      public $user_fname;
      public $user_email;
      public $user_password_hash;
      /**
       * @inheritdoc
       */
  
  
      public function rules()
      {
          return [
              [['user_fname','user_email', 'user_password_hash'], 'required'],
              // rememberMe must be a boolean value
  
              ['user_password_hash','match','pattern'=&gt;'$\S*(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$','message'=&gt;'Password must have atleast 1 uppercase and 1 number '],
              [['user_password_hash'],'string','min'=&gt;6],
              //email validation
              ['user_email','email']
              [['user_email'], 'string', 'max' =&gt; 255],
              [['user_fname'], 'string', 'max' =&gt; 45],
          ];
      }
      /**
       * Signs user up.
       *
       * @return User|null the saved model or null if saving fails
       */
      public function signup()
      {
          if (!$this-&gt;validate()) {
              return null;
          }
  
          $user = new SimUser();
          $user-&gt;user_fname = $this-&gt;user_fname;
          $user-&gt;user_email = $this-&gt;user_email;
          $user-&gt;setPassword($this-&gt;user_password_hash);
          $user-&gt;generateAuthKey();
          $user-&gt;save();
  
          return $user;
      }
  } 
  </code></pre>
  
  <p><strong>Site Controller.php/signup method</strong></p>
  
  <pre><code>public function actionSignup()
      {
          $model = new SignupForm();
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
              if ($user = $model-&gt;signup()) {
                  if (Yii::$app-&gt;getUser()-&gt;login($user)) {
                      return $this-&gt;goHome();
                  }
              }
          }
          return $this-&gt;render('signup', [
              'model' =&gt; $model,
          ]);
      }
  </code></pre>
  
  <p><strong>my view file</strong></p>
  
  <pre><code>&lt;?php
  /* @var $this yii\web\View */
  /* @var $form yii\bootstrap\ActiveForm */
  /* @var $model \frontend\models\SignupForm */
  use yii\helpers\Html;
  use yii\bootstrap\ActiveForm;
  $this-&gt;title = 'Signup';
  $this-&gt;params['breadcrumbs'][] = $this-&gt;title;
  ?&gt;
  &lt;div class="site-signup"&gt;
      &lt;h1&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
  
      &lt;p&gt;Please fill out the following fields to signup:&lt;/p&gt;
  
      &lt;div class="row"&gt;
          &lt;div class="col-lg-5"&gt;
              &lt;?php $form = ActiveForm::begin(['id' =&gt; 'form-signup']); ?&gt;
  
                  &lt;?= $form-&gt;field($model, 'user_fname')-&gt;textInput() ?&gt;
  
                  &lt;?= $form-&gt;field($model, 'user_email')-&gt;textInput() ?&gt;
  
                  &lt;?= $form-&gt;field($model, 'user_password_hash')-&gt;passwordInput() ?&gt;
  
                  &lt;div class="form-group"&gt; 
                      &lt;?= Html::submitButton('Signup', ['class' =&gt; 'btn btn-primary', 'name' =&gt; 'signup-button']) ?&gt;
                  &lt;/div&gt;
  
              &lt;?php ActiveForm::end(); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My User file, this s the file to which the data has to be posted.. I retrieve login details from here.
  
  
  <pre><code>namespace app\models;
  
  use Yii;
  
  /**
   * This is the model class for table "sim_user".
   *
   * @property integer $user_id
   * @property string $user_email
   * @property string $user_password_hash
   * @property string $user_fname
   * @property string $user_lname
   * @property integer $user_company
   * @property string $user_authcode
   * @property integer $user_suspended
   * @property string $user_created
   * @property integer $user_deleted
   * @property string $user_auth_key
   * @property string $user_access_token
   */
  class SimUser extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'sim_user';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['user_email', 'user_password_hash']],
              [['user_company', 'user_suspended', 'user_deleted'], 'integer'],
              [['user_created'], 'safe'],
              [['user_email'], 'string', 'max' =&gt; 255],
              [['user_password_hash'], 'string', 'max' =&gt; 20],
              [['user_fname', 'user_lname'], 'string', 'max' =&gt; 45],
              [['user_auth_key'], 'string', 'max' =&gt; 32],
              [['user_access_token'], 'string', 'max' =&gt; 100],
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'user_id' =&gt; Yii::t('app', 'User ID'),
              'user_email' =&gt; Yii::t('app', 'User Email'),
              'user_password_hash' =&gt; Yii::t('app', 'User Password Hash'),
              'user_fname' =&gt; Yii::t('app', 'User Fname'),
              'user_lname' =&gt; Yii::t('app', 'User Lname'),
              'user_company' =&gt; Yii::t('app', 'User Company'),
              'user_authcode' =&gt; Yii::t('app', 'User Authcode'),
              'user_suspended' =&gt; Yii::t('app', 'User Suspended'),
              'user_created' =&gt; Yii::t('app', 'User Created'),
              'user_deleted' =&gt; Yii::t('app', 'User Deleted'),
              'user_auth_key' =&gt; Yii::t('app', 'User Auth Key'),
              'user_access_token' =&gt; Yii::t('app', 'User Access Token'),
          ];
      }
  
     public function getAuthKey() {
          return $this-&gt;user_auth_key;
      }
  
      public function getId() {
          return $this-&gt;user_id;
      }
  
      public function validateAuthKey($authKey) {
         return $this-&gt;user_auth_key = $authkey;
      }
  
      public static function findIdentity($id) {
  
          return self::findOne($id);
  
      }
  
      public static function findIdentityByAccessToken($token, $type = null) {
  
          return $this-&gt;user_access_token;
      }
  
      public static function findByUsername($email){
          return self::findOne(['user_email'=&gt;$email]);
      }
  
      public function validatePassword($password){
          return $this-&gt;user_password_hash === $password;
      }
  
       public function setPassword($password)
      {
          $this-&gt;user_password_hash = Yii::$app-&gt;security-&gt;generatePasswordHash($password);
      }
  
  
      public function generateAuthKey()
      {
          $this-&gt;user_auth_key = Yii::$app-&gt;security-&gt;generateRandomString();
      }
  
      public function beforeSave($insert)
      {        
          if (parent::beforeSave($insert)) 
              {            
              if ($this-&gt;isNewRecord) 
                  {                
                  $this-&gt;user_auth_key = \Yii::$app-&gt;security-&gt;generateRandomString();            
  
                  }           
                  return true;        
              }        
              return false;   
      }
  
  }
  </code></pre>