How do you alter a form error? How do you alter or remove a form error produced by Drupal or another module on node insert/save, for a particular content type. I'm looking for a method which I can use in a module.

I've tried hook_node_validate(), but all I was able to do is to get errors and set errors.
Altering strings

To change the text of a single string, the simplest method is to use the String Overrides module. That would allow you to replace the string:


  "!name field is required."


with (for example):


  "The field '!name' is required."


Altering form fields

If you want to make a field not required, use a normal hook_form_alter() implementation:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_node_form_alter(&amp;$form, &amp;$form_state) {
  $node = $form['#node'];
  if ($node-&gt;type == 'my_custom_type') {
    $form['title']['#required'] = FALSE;
  }
}


Changing the way a form is validated

Forms have validation functions specified in the $form['#validate'] array. And form elements have functions specified in $form['element_key']['#element_validate'].

You can specify your own like this:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_node_form_alter(&amp;$form, &amp;$form_state) {
  $form['title']['#element_validate'][] = 'mymodule_validate_node_title';
}

/**
 * Validate the node title to prevent ALL CAPS.
 */
function mymodule_validate_node_title($element, &amp;$form_state, $form) {
  if (preg_match('/^[A-Z]+$/', $element['#value'])) {
    form_error($element, t('You may not enter titles in ALL CAPS.'));
  }
}