Uploadify: Passing a form's ID as a parameter with scriptData

梦想的初衷 提交于 2019-12-05 21:35:53

well I was struggling with the same issue just a minute ago and here is the solution, you can get the ID of the element as defining a function in onSelect event like below

//EDIT Here's the working code

$('.uploady').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploadify',
    'auto'      : true,
    // ANSWER
    'onSelect'    : function(event,ID,fileObj) {
        var elem_id = $(event.target).attr("id"); //here you get the id of the object.
        $("#"+elem_id).uploadifySettings('scriptData',{'formID':elem_id})
    },
});

now your formID would be sent correctly

If you know that you want it to be sent every time (or don't mind having it sent unnecessarily), you can make a simple edit to the Uploadify.js file.

Replace this if clause (beginning line 74 in Uploadify v2.1.4) :

if (settings.scriptData) {
    var scriptDataString = '';
    for (var name in settings.scriptData) {
        scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
    data.scriptData = escape(scriptDataString.substr(1));
}

with the following:

if (settings.scriptData) {
    var scriptDataString = '';
    for (var name in settings.scriptData) {
        scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
}
scriptDataString += '&elemID=' + settings.id;
data.scriptData = escape(scriptDataString.substr(1));

In the backend, the element ID can be accessed like any other element of scriptData:

$thisInputID = $_POST["elemID"];

If you want to access the ID with a different name (here, it's elemID), just change it in the scriptDataString += '&elemID=' + settings.id line, above.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!