How can I change message set on form.inc? I am using taxonomy module in my site and have used the "Add vocabulary" form by hook_form_alter().

I want to change the error message for machine name (Machine name in use) to some other message. This message and validation is thrown from form.inc function. How can I change this message in my hook_form_alter() function?

Some code

function resources_form_taxonomy_form_vocabulary_alter(&amp;$form, &amp;$form_state) {  
    if(strstr(current_path(), 'admin/structure/resources'))
    {       
        $form['#validate'][] = '_error_preservation_helper';

    }
}


function _error_preservation_helper($form, &amp;$form_state) {
debug(form_get_errors());   
    $errors = form_get_errors(); // works shows error array 
    if(is_array($errors) &amp;&amp; array_key_exists('machine_name', $errors))
    {
        // now change the error message
        form_set_error('machine_name', 'custom message', TRUE); // not works
    }
    debug(form_get_errors());   // same results 

}
It's notoriously difficult to target/replace specific messages in the Drupal system. It's not impossible but it's a bit 'messy'.

I'd strongly recommend instead that you install the String Overrides module and use that to replace the specific message instead. String Overrides:


  Provides a quick and easy way to replace any text on the site.


It is available for any string in the system which is passed through the t() function, which all core error messages are.