Put class error when I use validate I am working with the Metatags module, and I have these fields.



I need that looks like as in the following screenshot, when the fields meta description and meta keywords are validated.



This is my code, I don't know how can include the class error and put the * symbol.  My question is related with styles.  I want the field keywords and description looks as fields required for the user.

mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form_id = $form['form_id']['#value'];
  if ($form_id == "article_node_form") {
    $form['#validate'][] = 'mymodule_test_validation';
  }
}

function mymodule_test_validation($form, &amp;$form_state) {
   if (($form_state['values']['metatags']['description']['value'] == '')) {
        form_set_error('Description', t('field is required'));
      } 
      if (($form_state['values']['metatags']['keywords']['value'] == '')) {
        form_set_error('Keywords', t('field is required'));     
      }
}
If the only validation you are looking for is to make sure the fields are required, then you don't need to call to a validation function. The solution in that case will be to set the "required" attribute to TRUE for the fields description and keywords in the "form_alter" function. This solution will give you the style you are looking for in the required fields.

Something like this (this is a proof of concept):

mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form_id = $form['form_id']['#value'];
  if ($form_id == "article_node_form") {
    // Make META DESCRIPTION required
    $form['metatags']['description'] = array('#require' =&gt; TRUE,);

    // Make META KEYWORDS required
    $form['metatags']['keywords'] = array('#require' =&gt; TRUE,);
  }
}


To get the right field names do the following:

mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form_id = $form['form_id']['#value'];
  if ($form_id == "article_node_form") {

   print_r($form);

  }
}