I have created some meta boxes of pages on the theme i'm working on.
The idea is to have a input field, then a button to upload files.
The meta box is working properly.
When I click on the button, it fires the thickbox.
This is working fine too.
Then I could upload a media or choose a media for the library.
A little bit of jQuery need to grab the URL of the chosen file in ThickBox and put it in the correct field.
I had a script which works fine with images, but it's not working on PDF files.
//lauch on click to appropriate button
jQuery('#upload_requestform_button').click(function() {
// keep copy of the original send to editor
original_send_to_editor = window.send_to_editor;
//new send_to_editor function
window.send_to_editor = function(html) {
// i guess this where i'm wrong
imgurl = jQuery('img',html).attr('src');
// sending the data to the input
jQuery('#box_requestform_meta').val(imgurl);
tb_remove();
// restore send_to_editor to post content
window.send_to_editor = original_send_to_editor;
}
// loads thickbox
formfield = jQuery('#box_requestform_meta').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
and this is the HTML part :
<label for="ala_request_form_ID"><?php _e( "Request Form", 'Request Form' ); ?></label><br />
<input id="box_requestform_meta" type="text" size="80%" name="box_requestform_meta" value="<?php echo esc_attr( get_post_meta( $object->ID, 'box_requestform_meta', true ) ); ?>" />
<input id="upload_image_button" type="button" value="Upload Request Form" />
I couldn't find much documentation or examples about how to use thickbox, any help appreciated ^^