0

As the title suggests I need to remove the upload button from an imagefield form element within D7.

I can't seem to find the element itself within the form array (via hook_form_alter) and I'm just wondering if it needs to be done a different way perhaps.

(I do realise the button can be hidden with CSS but I'd rather not take that option if I can help it.)

  • are you trying to remove it so the user can't upload another file into this field? if so, there might be a better way to deal with this using permissions. – Jimajamma Dec 15 '11 at 18:55
  • Nope, I'm trying to remove the upload button on a particular form, much in the same way you would alter the submit button text via a form alter perhaps. So I'd still want the file browse input so users can select a file just not the upload button. – TEDavis Dec 16 '11 at 9:47
  • Ah, so you want the actual upload to happen only when the form is finally submitted, not after the file has been selected I guess. In any case, in D6 at least, this is all done within the filefield module's widget by theming it with theme_filefield_widget_file() so perhaps you can retheme it yourself. It's in filefield_widget.inc if you want to take a look at what it's doing. Or just use CSS :) – Jimajamma Dec 16 '11 at 17:22
  • After searching, the upload button is created via: file_managed_file_process() - and annoyingly there doesn't seem to be a way of overriding it. – TEDavis Dec 16 '11 at 18:59
3

Put this code in template.php of your theme, and rename the function.

/**
 * Implementation theme_image_widget($variables)
 */
function THEMENAME_image_widget($vars){
  unset($vars['element']['upload_button'], $vars['element']['remove_button']);
  return theme_image_widget($vars);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.