I would like to change the default error message from Drupal core.

The error message is "Please Select the Valid File Format".

My problem is in brief below.

  • I have created a CCK called 'Assignment'.
  • There I have given the users an option to upload files.
  • In such case if the user uploads invalid file format drupal will throw the error message as mentioned above.
  • I need to change the error message in to "The file upload field cannot upload the speicified filed".

How can I achieve this?

(Should not use string overrides module)

Thanks in advance..


5 Answers 5


If that string is run through the t() function (which is probably is) and you don't want to use String Overrides, then you can update your settings file.

For Drupal 6, putting this in your "settings.php" file should work.

$conf["locale_custom_strings_en"] = array(
  "Please Select the Valid File Format" => "The file upload field cannot upload the speicified filed",

In Drupal 7, you would change it to

$conf["locale_custom_strings_en"][""] = array(
  "Please Select the Valid File Format" => "The file upload field cannot upload the speicified filed",

However, I am not seeing the string "Please Select the Valid File Format" in any of my D6 installs, and that is not the message I get when try to upload to a CCK filefield with the wrong file type or the MIME type doesn't match the file extension.

  1. Get the messages using drupal_get_messages(). Make sure to leave the $clear_queue parameter at the default true.
  2. Search the resulting array for the relevant messages and replace them. The resulting array is indexed by message type and the values are arrays of messages for that type (even if you only retrieve messages of a particular type).
  3. Inject the messages back into the message queue using drupal_set_message().

Drupal retrieves the message queue in function theme_status_messages() which is called from template_preprocess_page(), so one place to achieve this would be an override of that theme function. Depending on the exact circumstances of the message, you might find some hook that is closer to the point when the message is generated.

Because the messages are rendered in template_preprocess_page(), an implementation of hook_exit() is not an option, because this hook is invoked when the page is already rendered.

BTW: I often wished for a hook_message_alter().


I placed the following code in template_preprocess_page() and it worked perfectly. I'm not totally convinced this is the best way to do it but it was faster than building a module to generate the custom errors.

To get this done I looked at all the error messages generated by drupal_get_messages() and cycled through them. If they matched the string I was looking for I would then use drupal_set_message() to generate the error with new text. The final step was to pass the remaining errors through drupal_set_message() otherwise they wouldn't be called.

Again I'm not certain this is the best way of pulling it off, if anyone has any suggestions on how to do this in the theme layer I'd love to hear them.

$getmsg = drupal_get_messages('error');
    if ($getmsg){
      foreach($getmsg['error'] as $err) {

          switch($err) {
          case 'SUBSCRIBE TO THE NEWSLETTER field is required.':
            drupal_set_message('Sorry, you must sign up to the newsletter to enter', 'error');
          case 'I AGREE WITH THE CONTEST RULES &amp; REGULATIONS</a> field is required.':
            drupal_set_message('Sorry, you must agree to the rules and regulations', 'error');
            drupal_set_message(t($err), 'error', FALSE);


The easiest way is to use the String Overrides module.

Install the module and you can replace the string with your own string. The string overrides module also allows you to replace any string wrapped in the t() function.

  • The OP specifically stated, not using the String Overrides module
    – Laxman13
    Commented Sep 29, 2011 at 13:17

Drupal 7

You can customize error messages by using Field validation per entity field.

To do that, edit field settings, go to Validation and add a new validation rule (Required field rule). There, you should have textfield to set-up Custom error message for that field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.