I want use Callback validation but continue_if_empty not working for File, it’s returning No file was uploaded error. But everything working for Input and 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);
}
This helped me to solve "No file was uploaded" error.
Include this line in your view template (.phtml) before you open form tag:
Full Example:
Source: https://docs.laminas.dev/laminas-form/file-upload/