5

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.

4 Answers 4

2

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>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried putting quotes around the value you wish to JSON encode? i.e. replacing $('#location').val() with "\'"+$('#location').val()+"\'".

Comments

0

Here the code for uploadify 3.1

$(function() {
    $('#file_upload').uploadify({
        'formData'      : {'id' : ''},
        'debug': false,         
        'buttonClass' : 'g-button g-button-blue',
        'swf'           : '../uploadify/uploadify.swf',
        'uploader'      : 'ajax/my_upload_file.php',
        'onUploadStart' : function(file) {
            $('#file_upload').uploadify('settings', 'formData', {'id' : $('#id').val() });
        }
    });
});

I need to use it because I call my form data with json and then I must update uploadify id post parameter

Comments

-1

You need to specify the method by which you're posting your variables:

In your uploadify config:

//...
'method': 'POST',
//...

2 Comments

I thought POST is default method, however it does not matter even after adding this.
that's rather strange, what version of uploadify are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.