Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1227
diff -u -p -r1.1227 common.inc
--- includes/common.inc	25 Sep 2010 02:00:06 -0000	1.1227
+++ includes/common.inc	25 Sep 2010 03:10:59 -0000
@@ -6004,6 +6004,9 @@ function drupal_common_theme() {
     'form_element_label' => array(
       'render element' => 'element',
     ),
+    'form_error_marker' => array(
+      'render element' => 'element',
+    ),
     'vertical_tabs' => array(
       'render element' => 'element',
     ),
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.495
diff -u -p -r1.495 form.inc
--- includes/form.inc	24 Sep 2010 21:36:22 -0000	1.495
+++ includes/form.inc	25 Sep 2010 03:10:59 -0000
@@ -1218,7 +1218,10 @@ function _form_validate(&$elements, &$fo
         // Instead of setting no #title, form constructors are encouraged to set
         // #title_display to 'invisible' to improve accessibility.
         if (isset($elements['#title'])) {
-          form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
+          form_error($elements, $t('<a href="#!field_id">!title</a> field is required.', array(
+            '!field_id' => $elements['#id'],
+            '!title' => $elements['#title'],
+          )));
         }
         else {
           form_error($elements);
@@ -3593,6 +3596,11 @@ function theme_form_element_label($varia
   // If the element is required, a required marker is appended to the label.
   $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';
 
+  // If the element has an error, append an error marker to the label. By
+  // default we append the error message text styled as invisible. This allows
+  // screen reader users to know which field has an error and what the error is.
+  $error = theme('form_error_marker', array('element' => $element));
+
   $title = filter_xss_admin($element['#title']);
 
   $attributes = array();
@@ -3610,7 +3618,50 @@ function theme_form_element_label($varia
   }
 
   // The leading whitespace helps visually separate fields from inline labels.
-  return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "</label>\n";
+  return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required !error', array('!title' => $title, '!required' => $required, '!error' => $error)) . "</label>\n";
+}
+
+/**
+ * Theme an invisible error marker within the label for form elements.
+ *
+ * For each form element with an error, this function outputs an error marker
+ * that is appended to the label next to each field. By default this outputs
+ * the error message text in an invisible span. This allows screen reader users
+ * to know which fields have an error and what the error is. Override this
+ * function if you want to provide a different error marker, such as visible
+ * error text or an icon with a tooltip.
+ *
+ * @param $variables
+ *   An associative array containing:
+ *   - element: An associative array containing the properties of the element.
+ *
+ * @return
+ *   A string with a marker to identify an error, otherwise an empty string.
+ *
+ * @ingroup themeable
+ */
+function theme_form_error_marker($variables) {
+  $element = $variables['element'];
+  // This is also used in the installer, pre-database setup.
+  $t = get_t();
+
+  $output = '';
+  if ($raw_error = form_get_error($element)) {
+    // This is the same test used to validate #required fields.
+    // @see _form_validate()
+    if ($element['#required'] && (!count($element['#value']) || (is_string($element['#value']) && strlen(trim($element['#value'])) == 0) || $element['#value'] === 0)) {
+      $error = $t('This field is required.');
+    }
+    else {
+      $error = strip_tags($raw_error);
+    }
+    $attributes = array(
+      'class' => array('element-invisible', 'error'),
+    );
+    $output .= ' <span' . drupal_attributes($attributes) . '>' . $error . '</span>';
+  }
+
+  return $output;
 }
 
 /**
Index: modules/field/tests/field.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/tests/field.test,v
retrieving revision 1.41
diff -u -p -r1.41 field.test
--- modules/field/tests/field.test	24 Sep 2010 00:37:42 -0000	1.41
+++ modules/field/tests/field.test	25 Sep 2010 03:10:59 -0000
@@ -1300,7 +1300,7 @@ class FieldFormTestCase extends FieldTes
     // Submit with missing required value.
     $edit = array();
     $this->drupalPost('test-entity/add/test-bundle', $edit, t('Save'));
-    $this->assertRaw(t('!name field is required.', array('!name' => $this->instance['label'])), 'Required field with no value fails validation');
+    $this->assertText(t('!title field is required.', array('!title' => $this->instance['label'])), 'Required field with no value fails validation');
 
     // Create an entity
     $value = mt_rand(1, 127);
@@ -1316,7 +1316,7 @@ class FieldFormTestCase extends FieldTes
     $value = '';
     $edit = array("{$this->field_name}[$langcode][0][value]" => $value);
     $this->drupalPost('test-entity/manage/' . $id . '/edit', $edit, t('Save'));
-    $this->assertRaw(t('!name field is required.', array('!name' => $this->instance['label'])), 'Required field with no value fails validation');
+    $this->assertText(t('!title field is required.', array('!title' => $this->instance['label'])), 'Required field with no value fails validation');
   }
 
 //  function testFieldFormMultiple() {
Index: modules/simpletest/tests/form.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form.test,v
retrieving revision 1.68
diff -u -p -r1.68 form.test
--- modules/simpletest/tests/form.test	24 Sep 2010 21:36:22 -0000	1.68
+++ modules/simpletest/tests/form.test	25 Sep 2010 03:10:59 -0000
@@ -66,7 +66,7 @@ class FormsTestCase extends DrupalWebTes
     $elements['file']['empty_values'] = $empty_strings;
 
     // Regular expression to find the expected marker on required elements.
-    $required_marker_preg = '@<label.*<span class="form-required" title="This field is required\.">\*</span></label>@';
+    $required_marker_preg = '@<label.*<span class="form-required" title="This field is required\.">\*</span>.*</label>@';
 
     // Go through all the elements and all the empty values for them.
     foreach ($elements as $type => $data) {
