Change error message attribute in ActiveForm

Hello,

i have an ActiveForm in which I can edit 2 rows of the same model, the labels are hidden because they are displayed in a table and the label is in the first column.

If there is an error, the message is in both rows the same. How can I change this?

->label("Stückzahl ".$jahr);

only changes the name of the label, but not the text in the error-message.

I would like to show an image of the problem, but attachments didn’t work and I can’t post an URL because this is my first post :(

You need change this in the model




    public function rules()

    {

        return [

            ['image', 'required','message'=>'It is required'],

        ];

    }



This is for if it is required, but you could put your function, for example:





  public function rules()

    {

        return [

            ['image', 'validateImage',]

        ];

    }

    public function validateImage($attribute, $params)

    {

            if (...) {

                $this->addError($attribute, 'Incorrect image.');

            }

        }

    }



In the images I use this :




public function rules()

    {

        return [['file', 'file','skipOnEmpty' => false,

            'uploadRequired' => '', //Error

    'maxSize' => 1024*1024*1, //1 MB

    'tooBig' => '', //Error

    'minSize' => 10, //10 Bytes

    'tooSmall' => '', //Error

    'maxFiles' => 10,

   'tooMany' => '', //Error

    ],]; 

        

    } 



but I think that you dont want this

The errors are for each atribute in the model, if you have two attributes in the model you have two errors,two validations differents ,

you can change all labels for the atributes in the model:




    public function attributeLabels()

    {

        return [

            'image' => 'The image',

            'name' => 'The name',

        ];

    }



Thanks, but this is not the problem.

This is my problem, that in each row apples, bananas or oranges is a duplicate. I’d like to have „Apples 2015“ or sth like that. :rolleyes:

Now I have looked into ActiveField.php:




$this->parts['{error}'] = Html::error($this->model, $this->attribute, $options);



So I think it’s only possible when editing $this->attribute…