A
A
Alexander2015-09-10 11:18:31
Yii
Alexander, 2015-09-10 11:18:31

How to make rules dependent on another field in yii2?

In the registration form model, you need to check by phone or mail so that at least one of the fields is filled.
How to do it in feng shui yii, through scripts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
matperez, 2015-09-10
@jooow

It was here somewhere...

[['phone', 'email'], 'required',
                'when' => function () {
                    if (!$this->phone && !$this->email) {
                        $this->addError('phone', 'Необходимо указать либо телефон, либо email.');
                        $this->addError('email', 'Необходимо указать либо телефон, либо email.');
                    }
                },
                'whenClient' => 'function (attribute, value) { return !$(\'#order-phone\').val().length && !$(\'#order-email\').val().length ;}',
                'message' => Yii::t('app', 'Необходимо указать либо телефон, либо email.')
            ],

V
vyachin, 2015-09-10
@vyachin

1. write your own validator
2. use www.yiiframework.com/doc-2.0/yii-validators-valida...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question