As part as a widget I'm creating, I need the admin to upload an image via the widgets panel I have the following code under a new class
<?php
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'qrimage'=> '');
$qrimage=$instance['qrimage']; ?>
<label for="<?php echo $this->get_field_id('qrimage'); ?>">
Upload QR Image:
<input class="wide"
id="<?php echo $this->get_field_id('qrimage'); ?>"
name="<?php echo $this->get_field_id('qrimage'); ?>"
type="text"
value='<?php echo attribute_escape($qrimage); ?>' />
Upload Image
<label for="uploadi<?php echo $this->get_field_id('qrimage'); ?>">
<input class="uploadi<?php echo $this->get_field_id('qrimage'); ?>"
name="uploadi<?php echo $this->get_field_id('qrimage'); ?>"
id="uploadi<?php echo $this->get_field_id('qrimage'); ?>"
value="Upload Image" type="button" />
</label>
<script type="text/javascript">
var formfield = '';
var imgurl ='';
jQuery(document).ready(function() {
jQuery('.uploadi<?php echo $this->get_field_id('qrimage');?>').click(function() {
formfield = jQuery('#<?php echo $this->get_field_id('qrimage'); ?>').attr('name');
tb_show('', 'media-upload.php?type=image&&TB_iframe=1');
return false;
});
// send url back to plugin editor
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#<?php echo $this->get_field_id('qrimage'); ?>').val(imgurl);
tb_remove();
}
});
</script>
Thing is... if I have 1 instance of the widget on the widgets panel , everything works fine.
Once I add another instance, everything's working on the first instance but on the second one I cannot save the image , The text field gets the value but on save it just disappears
Any thoughts why?
Thanks