开发者

Add a message when a CCK filefield file is uploaded

Just got a usability issue with a site I'm developing, and I'm pondering how to address it.

I'm using a CCK imagefield开发者_如何学运维 within a node that is used as a content profile. The field allows users to upload an avatar.

I've found that a few people tend to upload an image, but fail to save the node. I guess it's because the new image appears there, and it's easy for someone just to assume it's been uploaded and saved and navigate away from the page.

So... one idea I had was to print a 'image uploaded, save the the page to confirm changes' message below the CCK field when an image is uploaded. Is this even possible?


That's what worked for me

===

function theme_filefield_widget_preview($item) {
  // Remove the current description so that we get the filename as the link.
  if (isset($item['data']['description'])) {
    unset($item['data']['description']);
  }

  $warning = $item['status'] ? '' : '<font color="red">Please click \'Save\' below to save these changes</font>';

  return '<div class="filefield-file-info">'.
           '<div class="filename">'. theme('filefield_file', $item) .'</div>'.
           '<div class="filesize">'. format_size($item['filesize']) .'</div>'.
           '<div class="filemime">'. $item['filemime'] .'</div>'.
           "<p>$warning</p>".
         '</div>';
}


Couple options:

1) Custom module

2) Rules and actions (action is 'show user message' or something similar)


You can override the theme_filefield_widget_preview() function from the filefield_widget.inc file. Just copy the function to your template.php file, rename it to phptemplate_filefield_widget_preview(), then change anything as necessary.

// Also you can try to rename to [MY_THEME]_filefield_widget_preview()

function phptemplate_filefield_widget_preview($item) {

  // Remove the current description so that we get the filename as the link.
  if (isset($item['data']['description'])) {
    unset($item['data']['description']);
  }

  return '<div class="filefield-file-info">'.
           '<div class="filename">'. theme('filefield_file', $item) .'</div>'.
           '<div class="filesize">'. format_size($item['filesize']) .'</div>'.
           '<div class="filemime">'. $item['filemime'] .'</div>'.
           // Custom block
           '<div class="my-custom-class">'. t('Changes made in this table will not be saved until the form is submitted.') .'</div>'.

         '</div>';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜