Display custom field in the image lightbox


#1

Hi ! I have added a custom field in the rtmedia uploader (called “city”), and I would like this field to be displayed in the lightbox, after the image upload, so that we can see in the lighbox the city writen by the user.

Here is the code added in functions.php:

function custom_data() {
        global $rtmedia_media;
        ?>  <div> city :<input class="city" id="city" type="text" name="city" value="" /> </div>
        <?php
        }
        
add_action('rtmedia_uploader_before_start_upload_button', 'custom_data');

And I have also added this code in my js file but it still doesn’t work:

(function($) {
"use strict";
$(document).ready(function() {
// Add custom field after file upload
    rtMediaHook.register(
        'rtmedia_js_after_file_upload',
        function (args ) {
			
var donnees = $(this).serialize();     
$.ajax({
       type: "POST",
       url: "../../../plugins/buddypress-media/templates/media/media-single.php",
       data: donnees,
	   success : function(data){
	      $("#texte_a_inserer").html(data);
        }
	});
		});
});
})(jQuery);

Thanks a lot for your help! Marine


#3

Hi @marineb,

This is Mangesh from rtMedia team.

we have created the following code snippet which will solve your issue. Try this and let me know if it’s working for you or not.


#4

Hi @mangeshp ,

Thank you very much for all your work. I just have a question : It works very well when we upload a media from the activity page of the website, but I use the uploader shortcode on another page to upload the files, and it doesn’t work in that case. How should I modify this code to enable it to work with the uploader from the shortcode?

Thanks again, Marine


#5

When put this code in my functions.php theme they give me blank screen, any help?


#6

Plase help, maybe syntax php error?


#7

Hi @Webmaster_Topqueens,

The given code is tested and it is working fine. Will you please provide the error log which will help us to identify the error. Also, make sure your rtMedia plugin is active.

Looking forward to hearing from you.

Also, I have modified the code little bit. Please take the updated code and place it in your functions.php file.

Thanks, Mangesh


#8