Invalid validation rule: a rule must specify both attribute names and validator type

I keep getting the following error:

Invalid validation rule: a rule must specify both attribute names and validator type.

My rules are the following but I don’t see why full_legal_name is throwing this error since I have a name and a validator.

public function rules()
{
return [
[[‘full_legal_name’], ‘string’, ‘max’ => 100],
[[‘retracted’, ‘status’, ‘representative’], ‘integer’],
[[‘retracted’, ‘representative’], ‘boolean’],
[[‘retracted_datetime’], ‘default’, ‘value’ => null],
[[‘retracted_datetime’, ‘create_time’, ‘modified_time’], ‘datetime’, ‘format’=>‘php:Y-m-d H:i:s’],
[[‘email’, ‘email’], ‘max’ => 50],
[[‘representative’, ‘full_legal_name’, ‘email’], ‘required’]
];
}

misplaced ‘email’

3 Likes

I’m not sure what you are saying here.

You have two arguments but obviously your intention was three.

I thought this meant to create a rule that my variable ‘email’ was of type email with a maximum length of 50 characters.

Use your own first rule as example.

ok so I cannot use the max in the email validator rule itself. I have to check the max on the string validation, not the email validation.

Thanks, that seems to have fixed it.

Have a look here
https://www.yiiframework.com/doc/api/2.0/yii-base-model#rules()-detail