Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit additional Form Data to Blueimp Uploader?

I am trying to insert additional Form Data to MYSQL via Blueimp jquery file uploader. But I have some problems.

I am using demo settings and I changed my template-upload to following code (* I added Notunuz input)

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td class="preview"><span class="fade"></span></td>
        <td class="title"><label>Notunuz: <input name="title[]"></label></td>
        {% if (file.error) { %}
            <td class="error" colspan="2"><span class="label label-important">Hata</span> {%=file.error%}</td>
        {% } else if (o.files.valid && !i) { %}
            <td>
                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
            </td>
            <td class="start">{% if (!o.options.autoUpload) { %}
                <button class="btn btn-primary">
                    <i class="icon-upload icon-white"></i>
                    <span>Başlat</span>
                </button>
            {% } %}</td>
        {% } else { %}
            <td colspan="2"></td>
        {% } %}

    </tr>
{% } %}
</script>
  • How to get additional Form Data?
  • How to change .js and UploadHandler.php file?

My second question is How to redirect to specific URL upload is done?

like image 907
Devrim Avatar asked Dec 13 '12 20:12

Devrim


2 Answers

There are multiple ways for sending additional FormData,

1.Static Form Data (If the formdata are never changed on runtime) :

Initialize FileUpload using ,

 $('#fileupload').fileupload({
         formData: {
            "data1": data1,
            "data2": data2
        }
     });

2.Dynamic FormData

Use fileuploadsubmit for setting FormData on submit event

$('#formData').fileupload({
   .........
}).on('fileuploadsubmit', function (e, data) {
    data.formData = {
         "data1": data1,
         "data2": data2
    };
});

For More Details See :

like image 110
Runcorn Avatar answered Nov 15 '22 15:11

Runcorn


I used like,

$('#fileupload').fileupload({
    formData: {example: 'test'}
});

To be more dynamic,

 <input type="text" name="name" value="" id="inpName" /> /* example 1 */
 <span id="spnHash" style="display:none">ttt-vvv-hh</span> /* example 2 */
 $('#fileupload').fileupload({
    var $formData = {
        "name": $("#inpName").val(),
        "hash": $("#spnHash").text()
    }
     formData: $formData
 });

For redirect:

https://github.com/blueimp/jQuery-File-Upload/issues/670#issuecomment-2291997

like image 36
sk8terboi87 ツ Avatar answered Nov 15 '22 14:11

sk8terboi87 ツ