1

I am NOT having trouble passing something into my database, so the "may have already been answered" alert above and the associated link do not answer my question (Thanks for trying to help anyway). My problem is with the jquery variable.

Why is it when I pass $('input[name="ageLimit"]:checked', '#myForm').val() to the alert the variable pulls the correct information, but when I pass it to the url in the plupload function it does not and I end up with undefined in my database. Why might this be happening? permissions? jquery conflict?

<script type="text/javascript">
// Convert divs to queue widgets when the DOM is ready
$(document).ready(function(){ 
   $('#myForm input').on('click', function() {
   alert($('input[name="ageLimit"]:checked', '#myForm').val()); 
   });

});

$(function() {
$("#uploader").plupload({
    // General settings
    runtimes : 'flash,html5,browserplus,silverlight,gears,html4',       
    url : 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val(),
    max_file_size : '1000mb',
    max_file_count: 20, // user can add no more then 20 files at a time
    chunk_size : '1mb',
    rename: true,
    multiple_queues : true,
     //multipart_params : {
          //  aud : $('input[name="ageLimit"]').val()
    //},

    // Resize images on clientside if we can
    //resize : {width : 320, height : 240, quality : 90},

    // Rename files by clicking on their titles
    rename: true,

    // Sort files
    sortable: true,

    // Specify what files to browse for
    filters : [
        {title : "Image files", extensions : "jpg,gif,png"},
        {title : "Zip files", extensions : "zip,avi"}
    ],

    // Flash settings
    flash_swf_url : 'plupload/js/plupload.flash.swf',

    // Silverlight settings
    silverlight_xap_url : 'plupload/js/plupload.silverlight.xap'
});

// Client side form validation
$('form').submit(function(e) {
    var uploader = $('#uploader').plupload('getUploader');

    // Files in queue upload them first
    if (uploader.files.length > 0) {
        // When all files are uploaded submit form
        uploader.bind('StateChanged', function() {
            if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                $('form')[0].submit();
            }
        });

         //uploader.bind('BeforeUpload', function(up) {
             // up.settings.multipart_params.aud = $('input[name="ageLimit"]').val();
       // });    
        uploader.start();
    } else
        alert('You must at least upload one file.');

    return false;
});


});
</script>

here is the php code

//check for audience
    $aud = (!empty($_GET['aud'])) ? trim($_GET['aud']): "";
artsyL
  • 49
  • 1
  • 13
  • I suspect you can't pass URL-parameter GET data and multipart POST data at the same time -- or else you're retrieving it wrong server-side. Perhaps you're trying to retrieve a POST variable in your PHP, or perhaps plupload is stripping out your URL variables. – Blazemonger Nov 19 '13 at 17:15
  • 1
    How do you handle the GET-parameters? Please show your PHP code. – Marcel Korpel Nov 19 '13 at 17:16
  • the multipart data has been commented out for debugging. – artsyL Nov 19 '13 at 17:17
  • //check for audience $aud = (!empty($_GET['aud'])) ? trim($_GET['aud']): ""; – artsyL Nov 19 '13 at 17:19
  • [Here's a similar question on the plupload forum](http://www.plupload.com/punbb/viewtopic.php?id=1836), and a [simiar SO question](http://stackoverflow.com/questions/9535462/how-to-send-additional-data-using-plupload). – Blazemonger Nov 19 '13 at 17:21
  • This is passing "": uploader.bind('BeforeUpload', function(up) { up.settings.multipart_params = { aud : $('input[name="ageLimit"]').val() }; I have actually tired this before. Doing it through url seems to be the only thing that passes anything at all. }); I also changed the url back to the original code "upload.php" – artsyL Nov 19 '13 at 17:28
  • I also changed the php to $_REQUEST still no go – artsyL Nov 19 '13 at 17:32
  • Now it only pulls the first value: multipart_params : { aud : $('input[name="ageLimit"]').val() }, Why would the alert be correct and the multipart_params be incorrect? – artsyL Nov 19 '13 at 17:38
  • 1
    `(isset($_GET['aud']) && !empty($_GET['aud']))` – Marc B Nov 19 '13 at 19:57
  • @MarcB No, that's not necessary: [`empty`](http://php.net/empty) will first check if the variable is set. – Marcel Korpel Nov 20 '13 at 14:32

1 Answers1

2

I guess that is because no radio button is checked yet when the url option is evaluated in the init of the uploader.

instead of

url : 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val(),

have

url : 'upload.php',

then add, after the plupload call and before the $('form').submit( call :

var uploader = $('#uploader').plupload('getUploader');

uploader.bind('BeforeUpload',function(upldr,file){
    upldr.settings.url = 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val();
    // here some runtimes might need a upldr.refresh(); (Though I'm not sure, I guess I remember Flash would.)
    }
);

Hope this will help

jbl
  • 15,179
  • 3
  • 34
  • 101