Appending ID to file upload many on my images

Appending ID to file upload many on my images

kumamarikumamari Posts: 24Questions: 9Answers: 1

I am trying to append an ID to an array that gets submitted to my server side script. Basically, I change one of many images on my edit, then when that happens it goes to my script which receives a POST array with the name for the file upload many as follows.

I see this in my network tab on my developer tools.

array(2) {
  ["action"]=>
  string(6) "upload"
  ["uploadField"]=>
  string(9) "secondary"
}

How do I append the id of the actual row to this array?

This question has an accepted answers - jump to answer

Answers

  • kumamarikumamari Posts: 24Questions: 9Answers: 1
    edited September 2017

    Here is the code for my editor.

            label: "Secondary Images:",
            name: "secondary",
            type: "uploadMany",
            display: function (file_id) {
                // console.log(file_id);
                // Let's refresh the cached image! What a pain this was to figure out.
                var d = new Date();
                return '<div class="secondaryContainer"><img class="imageCollect" src="image.jpg"/></div>';
    
            },
            clearText: "Remove Image",
            noFileText: 'No image'
        }, {
            name: "DT_RowId",
            type: "hidden"
        }]
    
  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin
    Answer ✓

    The reason that the row id isn't sent is that you can upload an image in the create action. At that point the row doesn't have an id since it doesn't exist in the database at that time.

    You could use the ajaxData option of the upload field type to add the row id, but as I say, that will only work for an edit, not a create.

    Allan

  • kumamarikumamari Posts: 24Questions: 9Answers: 1
    edited September 2017

    Thanks for the tip allan! I found a working example of how to get this to work.

    How you would do it is as follows.

    label: "Secondary Images:",
        name: "secondary",
        type: "uploadMany",
        display: function (file_id) {
            // Let's refresh the cached image! What a pain this was to figure out.
            var d = new Date();
            return '<div class="secondaryContainer"><img class="imageCollect" src="image.jpg"/></div>';
        },
        clearText: "Remove Image",
        noFileText: 'No image',
        ajaxData: function (data) {
            data.append('id', editor.val('DT_RowId'));
        }
    }
    
This discussion has been closed.