diff --git a/docs/guide/input-validation.md b/docs/guide/input-validation.md index 5f9d8c2..7b0c155 100644 --- a/docs/guide/input-validation.md +++ b/docs/guide/input-validation.md @@ -342,11 +342,11 @@ by calling `validateValue()`. ### Handling Empty Inputs -Validators often need to check if an input is empty or not. You may call [[yii\validators\Validator::isEmpty()]] +Validators often need to check if an input is empty or not. In your validator, you may call [[yii\validators\Validator::isEmpty()]] to perform this check. By default, this method will return true if a value is an empty string, an empty array or null. Users of validators can customize the default empty detection logic by configuring -the [[yii\validators\Validator::isEmpty]] property. For example, +the [[yii\validators\Validator::isEmpty]] property with a PHP callable. For example, ```php [ @@ -356,6 +356,16 @@ the [[yii\validators\Validator::isEmpty]] property. For example, ] ``` +When input data are submitted from HTML forms, you often need to assign some default values to the inputs +if they are empty. You can do so by using the [default](tutorial-core-validators.md#default) validator. For example, + +```php +[ + // set "level" to be 1 if it is empty + ['level', 'default', 'value' => 1], +] +``` + ## Client-Side Validation