How to submit additional Form Data to Blueimp Uploader?
Asked Answered
M

4

15

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?

Militarize answered 13/12, 2012 at 20:45 Comment(4)
second q-n is simple add to done handler something like location.href=new_urlBroch
how to submit additional form data from plugin documentation....Broch
Thanks for your helps. How do you retrieve title server side through UploadHandler.php? I need to know this.Militarize
print_r($_POST) and you will see all data that you sentBroch
B
3

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 :

Bulahbulawayo answered 26/1, 2015 at 11:32 Comment(0)
A
1

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

Adventuress answered 20/12, 2012 at 6:31 Comment(0)
A
0
    $('#file-upload').fileupload({
      formData: {key: 'value'}
    });
Agnola answered 1/6, 2015 at 12:42 Comment(0)
D
0

Add an input element inside the fileupload form like the following:

<form id="fileupload" action="/server/php" method="POST" enctype="multipart/form-data">
    <input type="text" name="additional_data" value="your_value" hidden >
</form>

Then inside the UploadHandler.php you can get the value of your input using $_REQUEST['additional_data']

for example:

$myData = $_REQUEST['additional_data'];

and then insert data to mysql:

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->query("INSERT INTO your_tbl(your_field) VALUES ('$myData')");
Disposition answered 9/7, 2016 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.