How can I alter Clientside Validation error message?

By default it is showing 'Firstname field is required.' as required field validation error.

I want to change it in to 'A response is required.'.

Without changing the core how can I do that? Please help me.

Comments

attiks’s picture

There're theme functions you can use, check the docs, or leave a comment if it isn't clear

ARUN AK’s picture

Hi,

I altered the error message like this.

I added the following function in my theme's template.php:

/**
 * Customizing Validation messages.
 * @param type $variables
 * @return string
 */
function mytheme_status_messages($variables) {
  $display = $variables['display'];
  $output = '';

  $status_heading = array(
    'status' => t('Status message'),
    'error' => t('Error message'),
    'warning' => t('Warning message'),
  );
  foreach (drupal_get_messages($display) as $type => $messages) {
    $output .= "<div class=\"messages $type\">\n";
    if (!empty($status_heading[$type])) {
      $output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
    }
    if (count($messages) > 1) {
      $output .= " <ul>\n";
      foreach ($messages as $message) {
            $found1 = stripos($message,'field is required.');
            if($found1 !== false)
                $message = 'A response is required.';
                
            $output .= '  <li>' . $message . "</li>\n";
      }
      $output .= " </ul>\n";
    }
    else {
        $found1 = stripos($messages[0],'field is required.');
        if($found1 !== false)
            $messages[0] = 'A response is required.';
        $output .= $messages[0];
    }
    $output .= "</div>\n";
  }
  return $output;
}
ARUN AK’s picture

Issue summary: View changes
Status: Active » Closed (fixed)
hiranya’s picture

worked!