M
M
Maybe_V2016-05-26 00:17:45
Yii
Maybe_V, 2016-05-26 00:17:45

How to set custom message for invalid data entry in yii2 form field?

I'm using yii2 forms to get data from the user!
It is necessary for each form input field to draw its own conclusion about incorrectly entered data.
The model class looks like this:

<?php


namespace app\models;


use yii\base\Model;

class MyForms extends Model{

    public $name;
    public $email ;

    public function rules() {
        return [
           [['name' , 'email'], 'required', 'message' => 'имя не введено'],
            [['name' , 'email'], 'trim'],
            ['email', 'email', 'message'=> 'введите адрес']

        ];
    }

   public function attributeLabels(){
        return [

            'name' => 'Ваше ім’я',
            'email' => 'Електронна пошта',

        ];
    }

    public function getErrors($attribute = null)
    {
        return [
            'name' => ['не введенное имя'],
            'email' => ['не правильный адрес'],

        ];
    }


}

But for some reason the message passed for name is displayed! And getErrors I understand that he is not responsible for this either!
I ask for help for a newbie in yii))

How to implement it correctly?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim Timofeev, 2016-05-26
@prokopov-vi

message is responsible for displaying the message,
if for each separately it’s not the same as yours
and so

[['name'], 'required', 'message' => 'имя не введено'],
[['email'], 'required', 'message' => 'email не введен'],

but this
is not responsible for the mandatory email, but for matching the template, the presence of a dog, etc.

E
Evgeny Svirsky, 2015-08-21
@e_svirsky

https://www.artlebedev.ru/tools/decoder/

M
Matvey Mamonov, 2015-08-21
@eucalipt

Maybe the part that starts with == is added after? I don't think the ALL string is encoded. Only part of it before "=" is encoded.
s2uzsvlppntKmH6gHd0LTw
pOM0ihls4IiaxHlUyEBASw

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question