P
P
Padre2017-07-11 22:59:48
Yii
Padre, 2017-07-11 22:59:48

How to properly add custom form validation in yii2?

Learning the very basics of the framework tutorial https://github.com/yiisoft/yii2/blob/master/docs/g... there is a form validation model

namespace app\models;
use yii\base\Model;
class EntryForm extends Model
{
    public $name;
    public $email;
    public function rules()
    {
        return [
            [['name', 'email'], 'required'],
            ['email', 'email'],
        ];
    }
}

Question: where is the functionality of checking email for compliance with the email format hidden and where do you need to add classes / code to implement your own filter, for example, checking for the correct phone number?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry, 2017-07-11
@yii16

Good evening.
One
Two
Check e-mail
And for the phone, most likely, you need to write your own validator.
Follow the links to find information about custom validators.
For example, everything is in the same model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question