A
A
atomrus19932019-01-18 16:55:55
Yii
atomrus1993, 2019-01-18 16:55:55

How to make field validation only for guest in yii2?

There is a form, for example feedback.
There are fields:

  1. Name
  2. Email
  3. Message

How to make validation so that these fields are required for the guest (name, soap), but not for the user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
morricone85, 2019-01-18
@atomrus1993

The easiest way to do this is with scripts, for example:

$model = new Feedback;
if ( --условие-- ) {
    $model->scenario = Feedback::SCENARIO_GUEST;
}

in the model:
etc.

M
Maxim Timofeev, 2019-01-18
@webinar

Many options, you can have different models for different types of users, you can use: https://www.yiiframework.com/doc/api/2.0/yii-valid...
You can use scripts and https://www.yiiframework.com /doc/api/2.0/yii-valid...
There are probably more options, but I think these are enough

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question