drupal add class to form-item if error on form to all forms I just want to add class to .form-item if there is error on form i used the following code but its not working.

function semanticUI_form_element($variables) {
  if (isset($element['#parents']) &amp;&amp; form_get_error($element)) {
    $attributes['class'][] = array('error1');
  }
  if(form_get_error($element)){
    $attributes['class'][] = array('error1');
  }

  if (!empty($element['#required'])) {
    $element['#attributes']['class'][] = 'test';
  }
}


Any help would be appreciated.
If you copy the theme_form_element() function out of includes/form.inc and into your theme's template.php file, re-name it to match your theme, and change the initial setting of $attributes['class'] accordingly:

  if (form_get_error($variables['element'])) {
    $attributes['class'] = array('form-item', 'da-error');
  } else {
    $attributes['class'] = array('form-item'); 
  }


...this will put a da-error class in the overall &lt;div&gt; wrapping this element.