作为我正在创建的小部件的一部分,我需要管理员通过小部件面板上传图像我在一个新类下有以下代码
<?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>
事情是。。。如果我在widgets面板上有一个widget实例,那么一切都正常。一旦我添加了另一个实例,第一个实例上的一切都正常,但在第二个实例上,我无法保存图像,文本字段获得值,但在保存时它就消失了
有什么想法吗?为什么?
谢谢