Skip to main content
Indented code so it looks readable
Source Link
Letharion
  • 27.5k
  • 11
  • 83
  • 141

You can use hook_file_validate like this.

function mymodule_file_validate($file) {

if (form_get_errors()) {

function mymodule_file_validate($file) {  
  if (form_get_errors()) {

    // Save errors
    $form_errors = form_get_errors();
    $drupal_errors = drupal_get_messages('error');
    // Clear form errors
    form_clear_error();

    foreach($drupal_errors['error'] as $key => $error) {
      if (in_array($error, $form_errors)) {
        // Unset form errors
        unset($drupal_errors['error'][$key]);
      }
    }

    // Rebuild drupal errors
    foreach($form_errors as $key => $message) {
      if(strpos($message, 'old message') !== false) {
        $message = str_replace('old message', 'new message', $message);
        $_SESSION['messages']['error'][$key] = $message;
        form_set_error($key, $message);
      } else {
        form_set_error($key, $message);
      }
    }
  }
}

} }

I think it helps you.

You can use hook_file_validate like this.

function mymodule_file_validate($file) {

if (form_get_errors()) {

// Save errors
$form_errors = form_get_errors();
$drupal_errors = drupal_get_messages('error');
// Clear form errors
form_clear_error();

foreach($drupal_errors['error'] as $key => $error) {
  if (in_array($error, $form_errors)) {
     // Unset form errors
     unset($drupal_errors['error'][$key]);
  }
}

// Rebuild drupal errors
foreach($form_errors as $key => $message) {
  if(strpos($message, 'old message') !== false) {
    $message = str_replace('old message', 'new message', $message);
    $_SESSION['messages']['error'][$key] = $message;
    form_set_error($key, $message);
  } else {
    form_set_error($key, $message);
  }
}

} }

I think it helps you.

You can use hook_file_validate like this.

function mymodule_file_validate($file) {  
  if (form_get_errors()) {

    // Save errors
    $form_errors = form_get_errors();
    $drupal_errors = drupal_get_messages('error');
    // Clear form errors
    form_clear_error();

    foreach($drupal_errors['error'] as $key => $error) {
      if (in_array($error, $form_errors)) {
        // Unset form errors
        unset($drupal_errors['error'][$key]);
      }
    }

    // Rebuild drupal errors
    foreach($form_errors as $key => $message) {
      if(strpos($message, 'old message') !== false) {
        $message = str_replace('old message', 'new message', $message);
        $_SESSION['messages']['error'][$key] = $message;
        form_set_error($key, $message);
      } else {
        form_set_error($key, $message);
      }
    }
  }
}

I think it helps you.

Source Link
user30268
user30268

You can use hook_file_validate like this.

function mymodule_file_validate($file) {

if (form_get_errors()) {

// Save errors
$form_errors = form_get_errors();
$drupal_errors = drupal_get_messages('error');
// Clear form errors
form_clear_error();

foreach($drupal_errors['error'] as $key => $error) {
  if (in_array($error, $form_errors)) {
     // Unset form errors
     unset($drupal_errors['error'][$key]);
  }
}

// Rebuild drupal errors
foreach($form_errors as $key => $message) {
  if(strpos($message, 'old message') !== false) {
    $message = str_replace('old message', 'new message', $message);
    $_SESSION['messages']['error'][$key] = $message;
    form_set_error($key, $message);
  } else {
    form_set_error($key, $message);
  }
}

} }

I think it helps you.