Are you sure your form accepts file uploads? The form tag requires the attribute enctype="multipart/form-data"
On top of that, you should post some code so other can provide more solid help.
I'm trying to figure out a way to do the same thing, and looks like it's not that easy to implement file upload on frontend. The fact is, we can't send files over (basic) AJAX (XMLHttpRequest), like we do with textual form data, so, I see 2 ways to resolve the issue: the first one: get rid of AJAX in your form processing. Go traditional way with custom form processing controller/path. http://octobercms.com/docs/database/model#file-attachments and http://laravel.com/docs/requests#files would help in this case. Second way: learn how avatar backend widget (/backend/formwidgets/FileUpload.php) works. As far as I see, it's using jquery file upload plugin.
init: function ()
{
var
form = document.querySelector('form');
form.addEventListener('submit', function ( event )
{
event.preventDefault();
this.ajaxRequest( form );
}.bind( this ) );
},
inside ajax request method
ajaxRequest: function ( form )
{
var
handler = 'onSubmit',
formdata = new FormData( form ); // learn about this
$.ajax({
headers:
{
'X-OCTOBER-REQUEST-HANDLER': handler, // important
},
type: 'post',
cache: false,
contentType: false, // important
processData: false, // important
data: formdata,
success: function(data)
{
// do something
}
});
}
Uploader plugin from Responsiv works very well for me, but it could be nice to have sorting in next release. So far I made it with small changes in plugins files and using jquery ui sortable:
uploader.js line 179-180 func onUploadSuccess add line: $preview.attr('id', 'file-id-'+response.id) To have id on a newrly created element.
To the trait or ImageUploader component add fnc:
public function onSaveImagesOrder(){
$order = post('ord');
//print_r($order);
$orderArray = explode(',', $order);
if (is_array($orderArray)){
$n = 0;
foreach ($orderArray as $item){
$n ++;
$imageId = str_replace('file-id-', '', $item);
Db::table('system_files')
->where('id', $imageId)
->update(['sort_order' => $n]);
}
}
}
Maybe here not everything is perfect as I noticed cms saves order with larger numbers, but in case of one model record this should work. Also it might better to use system files model and edit it. who knows how?
Initialize sortable in some js file you add to component or page: