L
L
Lavrov952020-08-11 18:47:49
Zend Framework
Lavrov95, 2020-08-11 18:47:49

Why does continue_if_empty not work for FileInput?

I want to use Callbackbut continue_if_emptydoesn't work for File. But everything works for Inputand Select. I need help with this.

$this->add([
    'name' => 'images',
    'required' => false,
    'allow_empty' => true,
    'continue_if_empty' => true,
    'type' => FileInput::class,
    'filters' => [
        [
            'name' => Rename::class,
            'options' => [
                'target' => '/var/www/project/public/website/content/tmp/image_' . md5(time()),
                'randomize' => true,
            ],
        ],
    ],
    'validators' => [
        [
            'name' => Callback::class,
            'options' => [
                'callback' => [$this, 'imageValidator'],
            ],
        ],
     ],
]);


public function imageValidator($value, $context)
{
     dd($context);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
novrm, 2020-08-16
@novrm

/**
 * Configuration of the input filter for element based on the provided specification.
 * Specification can contain any of the following:
 *
 * .-------------------.----------------.-----------------.-----------------.--------------------.
 * | continue_if_empty | required       | allow_empty     | Is empty valid? | Apply other filter |
 * |-------------------+----------------+-----------------+-----------------+--------------------|
 * | false (default)   | true (default) | false (default) | false           | Not                |
 * | false (default)   | true (default) | true            | true            | Not                |
 * | false (default)   | false          | false (default) | true            | Not                |
 * | true              | true (default) | false (default) | true            | Yes                |
 * |-------------------+----------------+-----------------+-----------------+--------------------|
 * | false (default)   | false          | true            | true            | Not                |
 * | true              | true (default) | true            | true            | Yes                |
 * | true              | false          | false (default) | true            | Yes                |
 * | true              | false          | true            | true            | Yes                |
 * '-------------------'----------------'-----------------'-----------------'--------------------'
 */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question