Having trouble with validation of an image upload...
When "kategori" fails validation, it returns the error message...
but when the image upload fail, i get no error message.
so this is the validator in the controller...
PHP Code:
## Validation
$input = $this->validate([
'kategori' => 'required|min_length[3]|is_unique[kategori.kategori]',
'image' => 'uploaded[image]|max_size[image, 4]',
]);
//echo "<pre>input: "; print_r($input); echo "</pre>";
if (!$input) {
echo "failed";
return redirect()->to('/admin/cat/create')->withInput()->with('validation',$this->validator);
} else {
And this is the form view
PHP Code:
<?php $validation = \Config\Services::validation(); ?>
<div class="row">
<div class="col-md-12">
<form action="<?=site_url('admin/cat/store')?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="kategori">Kategori:</label>
<input type="text" class="form-control" name="kategori" required value="<?= old('kategori') ?>">
<!-- Error -->
<?php if( $validation->getError('kategori') ) {?>
<div class='alert alert-danger mt-2'>
<?= $error = $validation->getError('kategori'); ?>
</div>
<?php }?>
</div>
<div class="form-group">
<label for="image">Bilde:</label>
<input type="file" class="form-control" name="image" value="<?= old('image') ?>">
<!-- Error -->
<?php if( $validation->getError('image') ) {?>
<div class='alert alert-danger mt-2'>
<?= $error = $validation->getError('image'); ?>
</div>
<?php }?>
</div>
<button type="submit" class="btn btn-success" name="submit">Lagre</button>
</form>
</div>
I recon i got some error in my codingm, but i can't find it. Any help is appreciated.
Rgrds Bengt