I have a simple page with a form for files upload. I am validating it in controller and returning errors in the view if something goes wrong. Unfortunatelly, the alert with errors is always displaying (empty alert when no errors), even when I'm not submiting the form. Could someone please tell me how to do this in a better way?
form + error displaying:
<form enctype="multipart/form-data" method='POST' action='/add_image'>
<p>Wybierz zdjęcie do dodania:</p>
<input type="file" onchange='loadFile(event)' name='fileUpload' id='fileUploadInput'> <br> <br>
<img id="uploadPreview"> <br> <br>
<input type='submit' name='submit' id='fileUploadSubmit'>
</form>
@if($errors)
<script>alert('');</script>
@endif
validating:
if($request->hasFile('fileUpload')){
$image = $request->file('fileUpload');
$validator = Validator::make($request->all(), [
'fileUpload' => 'required|image',
])->validate();
}
$errors var_dump output without errors:
object(Illuminate\Support\ViewErrorBag)#147 (1) { ["bags":protected]=> array(0) { } }
I just want this alert to show when any errors are there...
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire