Answer the question
In order to leave comments, you need to log in
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' => ['не правильный адрес'],
];
}
}
getErrors
I understand that he is not responsible for this either! Answer the question
In order to leave comments, you need to log in
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 не введен'],
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 questionAsk a Question
731 491 924 answers to any question