Is it possible to require the user to enter alt text when they upload an image? I haven't found any way of achieving this.
To clarify: I don't want to use generated alt text, I want the user to enter custom alt text specific to the image when they upload an image, and to be able to edit this afterward. Currently this is possible, but if the user doesn't want to enter alt text they can simply leave the field blank. I'd like the option to make it a required field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kyeranr’s picture

I second this, It would be a useful feature.

quicksketch’s picture

I agree it would be useful also. This issue may be affected by #193887: Accessibility enhancements.

realityloop’s picture

Status: Active » Needs review
FileSize
589 bytes

Patch against head attached (if alt text is enabled then it is a required field)

andrewmacpherson’s picture

Status: Needs review » Needs work

James asked for the option to make it a required field. Realiltyloop's patch only allows a mandatory alt field, or no alt field at all.

I am strongly against making the ALT field compulsory wherever it is enabled, if that is the only option.

May I propose an alternative? Modify the ALT text settings settings form like so:

[ ] disabled
[ ] optional
[ ] required

Not every image requires ALT text, even where the image is meaningful rather than purely decorative. Having optional ALT text is very useful where images are used to accompany text, such as a blog-entry content-type, but it can also get in the way when the image accompanies well written text.

For a good explanation of the use case for optional ALT text, read The Alt and Accessibility.

For a good example of unnecessary ALT text, see the screenshot in Duke using Drupal ;-0

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
1.35 KB

Here's another patch; this one provides a disabled/optional/required setting for ALT text.

So far I've only tested it on a new installation of the ImageField module, not a site with existing fields. Looking at the widget_settings array, I don't think this will need an update function in imagefield.install

Have I missed something? I'm still learning CCK. Seems too easy.

span’s picture

Seems to work perfectly for me.

mrfelton’s picture

Status: Needs review » Needs work

Whilst the attached patch does add a red star to the field and make it look like it is required, I managed to add an image with no alt text regardless.

EDIT: Actually, I can create a NEW node with an imagefield that has no alt text, but I can't EDIT an existing one and leave the alt text blank. So.. I can create a new node, add an image (no alt text) and save. Then if I try to edit that node again I can not save until I enter something for the alt text.

mrfelton’s picture

Status: Needs work » Needs review
FileSize
1.21 KB

Try this version instead. The problem was in:

  // #value must be hard-coded if #type = 'value'.
  if ($default_alt) {
    $element['data']['alt']['#value'] = $field['widget']['alt'];
  }

Which should be rewritten as follows, since $default_alt does not really represent if type is #value:

  // #value must be hard-coded if #type = 'value'.
  if (!$field['widget']['custom_alt']) {
    $element['data']['alt']['#value'] = $field['widget']['alt'];
  }
mrfelton’s picture

Title: Make alt text required for each image » Ability to make alt and title text required for each image
FileSize
2.17 KB

I think this should be extended to the title field also. This means that for some imagefields we can mark both alt and title as required, ensuring quality meta data that is good for both search engines and humans.

My use case is that for certain imagefields (the lead image for a particular content type) I want to ensure that alt text is provided for search engines and I also want to ensure that a title tag is provided for captions. The ability to mark both of these attributes as required helps to ensure consistent site-wide tagging of images.

roalty’s picture

Patch #5 works well, but ALT field didn't really required like #7 said.

After changing

if ($default_alt) { to if (!$field['widget']['custom_alt']) { default values didn't show anymore. Field is clean.

PhilDHD’s picture

Thanks mrfelton, #9 worked perfectly for me.

skylord’s picture

#9 works OK - thank you.

quicksketch’s picture

Project: ImageField » ImageField Extended
Version: 6.x-3.x-dev » 6.x-4.x-dev

Considering ImageField has been moved into Drupal core and does NOT include this functionality, I think for the long-term sustainability of this feature this should be implemented in ImageField Extended, which will continue to exist in the Drupal 7 era. I'm moving this issue over there to see what the maintainer thinks of this idea.

Alan D.’s picture

Status: Needs review » Closed (duplicate)

I marking as a duplicate of #879512: List of feature requests - UX improvements. which would extend the functionality of the module significantly.

crea’s picture

Subs