SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uploadifive formdata results in PHP Undefined Index

    I have a form that after save shows the upload controls and I use 'JSON.stringify(myObject)' to generate a JSON object to pass to uploadifive so my upload.php file can create a db record, this resolves to {'record_type':'project','id':"1"}.

    php is reporting an undefined index for 'record_type' and 'id', the file itself uploads successfully. how do I pass the variable to uploadifive and execute it correctly so PHP can get access to the index values.

    For those that may be thinking PHP cannot read json natively, the plugin is suppose to convert JSON to a $_POST array.

    Code:
    $(document).ready(function () {
    ....... //some other code
    .......
    
       $(function(myUploadFormData){
        $('#file_input').uploadifive({                        
            'auto'              : false,
            'multi'             : false,
            'buttonClass'       : 'button',
            'formData'          : myUploadFormData,
            'buttonText'        : 'Select',
            'uploadLimit'       : 1,
            'queueID'           : 'droplist',
            'width'             : 75,
            'height'            : "25px",
            'queueSizeLimit'    : 1,
            'uploadScript'      : 'php/upload.php',
            'onUploadComplete'  : function(file, data) { console.log(data); }
         });
      });
    
      $("#file_upload").on("click", function() {
          $("#file_input").uploadifive('upload');
      });
    
    });
    
    function uploadFormData(id, record_type){
    var myObject = new Object();     
    myObject.record_type = record_type; 
    myObject.id = id;
    var myUploadFormData = JSON.stringify(myObject);
    }

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    This is a PHP related question more than anything since the error is occurring server side, could you please post your PHP code so we can get a picture of what's happening on the other side of the request.

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just resolved this using the following code to update the settings of the plugin. Uploadifive loaded on the initial display of the page when there was no record so formdata was 'undefined' defining the settings for formData just prior to upload has done the trick.

    Code:
    var record_id = $("#id").val();
        var record_type = "apples";
    
        $('#file_input').data('uploadifive').settings.formData = {'record_type': record_type,'record_id': record_id };


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •