我想将Dropzone用作另一个表单的文件输入框。
以下是使用<input type="file">
的代码,借助于Dropzone.js和Stackoverflow提供的帮助:
<form class="form-horizontal" action="/details/store" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="row">
<div class="form-group col-lg-6">
<label for="title" class="control-label col-lg-3 text-semibold">Title</label>
<div class="col-lg-9 {{ $errors->has('title') ? 'has-error' : '' }}">
<input name="title" type="text" class="form-control" value="{{ old('title') }}" required>
@if ($errors->has('title'))
<span class="help-block">{{ $errors->first('title') }}</span>
@endif
</div>
</div>
<div class="form-group col-lg-6">
<label for="subtitle" class="control-label col-lg-3 text-semibold">Sub Title</label>
<div class="col-lg-9">
<input name="subtitle" type="text" class="form-control" value="{{ old('subtitle') }}">
</div>
</div>
<div class="form-group col-lg-12">
<label for="description" class="control-label col-lg-1 text-semibold">Description</label>
<div class="col-lg-11">
<textarea name="description" class="form-control">{{ old('description') }}</textarea>
</div>
</div>
<div class="form-group col-lg-12">
<label for="images" class="control-label col-lg-1 text-semibold">Images</label>
<div class="col-lg-9" style="margin-left:4em;">
<span class="help-block text-semibold" style="color:blue">Accepted Formats: .jpg, .jpeg, .png, .gif</span>
<!-- Here is the file input I want to convert to dropzone -->
<input type="file" name="images[]" class="file-styled btn btn-primary" accept=".jpg, .jpeg, .png" required multiple>
<span class="help-block">Accepted formats: png, jpg, gif</span>
@if ($errors->has('images'))
<span class="help-block">{{ $errors->first('images') }}</span>
@endif
</div>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
我尝试过不同的方法来使用dropzone和div一起工作,例如:
<div action="#" id="dropzone" class="dropzone">
<div class="fallback">
<input type="file" name="images[]" class="file-styled btn btn-primary" accept=".jpg, .jpeg, .png" required multiple>
</div>
</div>
和JS
Dropzone.options.dropzone = {
url: "/properties/store",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
autoProcessQueue:false,
uploadMultiple:true,
paramName:"images",
maxFilesize:1,
maxFiles:10,
addRemoveLinks:true,
acceptedFiles: ".jpeg,.jpg,.png,.gif",
};
Dropzone被显示在表单中,甚至可以加载(和删除)图片,但是当我提交表单时,服务器端没有收到任何关于图片的数据。使用普通的
input type="file"
时,数据会按照需要被接收……
我无法理解在div中使用单独的action=""
和JS中的url:""
的用法,因为我不需要单独的URL来处理文件。我想通过表单的action路由一起提交它。
顺便说一下,我正在使用PHP-Laravel来处理服务器端。