Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending additional fields data with Uploadify

Tags:

jquery

php

I want to send some additional (form) fields data with uploadify. For this purpose, I am using scriptData. For example, following code sends the static values of name and location field correctly.

<script type="text/javascript">
$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed',
        'scriptData': {'name':'JohnDoe', 'location':'Australia'}

    });
});
</script>

However, as I have the input fields name and location, therefore I want to send the dynamic values. To do so, Im sending the values in ScriptData as following

'scriptData' : {'name' : $('#name').val(), 'location' : $('#location').val()}

And on upload.php, I'm trying

$name = $_GET['name'];
$location = $_GET['location'];

But it does not get any of the values. Please help me regarding this, how I can send additional fields data. Thanks.

like image 551
adam Avatar asked Nov 14 '22 02:11

adam


1 Answers

Because val()'s are called when DOM is loaded, not when a user types the location and name in. You should use one of the events to set new values. The manual isn't clear about it, I think it must be onSelectOnce event:

<script type="text/javascript">
$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed',
        'scriptData': {'name':'', 'location':''},
        'onSelectOnce' : function(event,data) {
            $("#fileUpload").uploadifySettings('scriptData', {'name' : $('#name').val(), 'location' : $('#location').val()});
        }
    });
});
</script>
like image 90
meze Avatar answered Dec 22 '22 04:12

meze