[[+content_image]]
G
G
Ghost26922018-02-16 21:55:53
Yii
Ghost2692, 2018-02-16 21:55:53

Doesn't throw an error for validation in Yii2?

Validation code:

public $contact;

    public function rules()
    {
        return [
            [['contact'], 'required', 'message' => Yii::t('app', 'The field does not have to be empty!')],
            [['contact'], 'string', 'min' => 4, 'message' => Yii::t('app', 'Contact should contain at least 4 characters.')],
        ];
    }

This code does not work, does not replace the message, how to solve?
[['contact'], 'string', 'min' => 4, 'message' => Yii::t('app', 'Contact should contain at least 4 characters.')],

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
Ghost2692, 2018-02-17
@Ghost2692

Found a solution, for the error message when there is 'min' => 4, 'tooShort' => "message error" displays an error, not 'message', well, for 'max' => 50 then 'tooLong' => "message error".

D
Dmitry, 2018-02-16
@slo_nik

Good evening.
Do you have such a line in the translation file?
Show translation file.
ps
In your translation file, in the returned array, there should be the following line:
And then in the validation rules, you can use it like this:
'message' => Yii::t('app', 'MIN_ERROR')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question