M
M
McMike2017-03-29 14:23:05
Yii
McMike, 2017-03-29 14:23:05

How to force validators not to work on an empty field?

Do not save the model because the string and unique validators return false if the field is empty.
How to overcome?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
padlyuck, 2017-03-29
@McMike

well, unique and should return false if there is already a record with such an empty field. As a matter of fact, without going into the details of the fact that you have some kind of crap there, look towards skipOnEmpty

[['field_name'], 'string', 'skipOnEmpty' => true], //у стринг валидатора по-умолчанию и так 'skipOnEmpty' => true

A
Alexey, 2017-03-29
@masterfreelance

Why validate empty fields?
Read about validation Checking incoming data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question