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.)

4
  • 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
    Commented Dec 15, 2011 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
    Commented Dec 16, 2011 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
    Commented Dec 16, 2011 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
    Commented Dec 16, 2011 at 18:59

1 Answer 1

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 and acknowledge you have read our privacy policy.

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