Welcome Guest, Not a member yet? Register   Sign In
Form Error : Remove 'The' Word from Error

I am beginner to Code Igniter. Recently I am working in form validation. I am using form validation error to check the error.

     $this->form_validation->set_rules('user_full_name', 'Name', 'trim|required|min_length[5]|max_length[50]|xss_clean');
  $this->form_validation->set_rules('user_email', 'Email', 'trim|required|valid_email');
     $this->form_validation->set_rules('comment', 'Suggestion limited to 255', 'trim|max_length[255]|xss_clean');
     if ($this->form_validation->run() == FALSE)

My requirement :

When error is displayed,it shows:
The Name field is required.
The Email field is required.

How can I remove 'The' from the error. Just I want to display as 'Name is required'

I tried to search the text in system/libraries/Form_validation.php file and remove 'The' word but could not get.

Can someone suggest me?
Thank you for you time.


Check the set_message() method in the Form Validation library documentation.

check http://ellislab.com/codeigniter/user-gui...tingerrors

Setting Error Messages

I went to Form Library to see set_message() but I could not find the text where these error are assigned.

[eluser]Sanjay Sarvaiya[/eluser]
You can do with this.
   $this->form_validation->set_rules('user_full_name', 'Name', 'trim|required|min_length[5]|max_length[50]|xss_clean');
   $this->form_validation->set_rules('user_email', 'Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('comment', 'Suggestion limited to 255', 'trim|max_length[255]|xss_clean');
     if ($this->form_validation->run() == FALSE) {    
      echo 'name requierd';
     else if(isset($this->form_validation->_error_array['user_email']))
      echo 'email required';

Create a language folder in your application directory and create the following file:


then place the following in that file:


$lang['required']   = "%s is required.";
$lang['isset']    = "%s must have a value.";
$lang['valid_email']  = "%s must contain a valid email address.";
$lang['valid_emails']  = "%s must contain all valid email addresses.";
$lang['valid_url']   = "%s must contain a valid URL.";
$lang['valid_ip']   = "%s must contain a valid IP.";
$lang['min_length']   = "%s must be at least %s characters in length.";
$lang['max_length']   = "%s can not exceed %s characters in length.";
$lang['exact_length']  = "%s must be exactly %s characters in length.";
$lang['alpha']    = "%s may only contain alphabetical characters.";
$lang['alpha_numeric']  = "%s may only contain alpha-numeric characters.";
$lang['alpha_dash']   = "%s may only contain alpha-numeric characters, underscores, and dashes.";
$lang['numeric']   = "%s must contain only numbers.";
$lang['is_numeric']   = "%s must contain only numeric characters.";
$lang['integer']   = "%s must contain an integer.";
$lang['regex_match']  = "%s is not in the correct format.";
$lang['matches']   = "%s does not match the %s field.";
$lang['is_unique']    = "%s must contain a unique value.";
$lang['is_natural']   = "%s must contain only positive numbers.";
$lang['is_natural_no_zero'] = "%s must contain a number greater than zero.";
$lang['decimal']   = "%s must contain a decimal number.";
$lang['less_than']   = "%s must contain a number less than %s.";
$lang['greater_than']  = "%s must contain a number greater than %s.";

/* End of file form_validation_lang.php */
/* Location: ./application/language/english/form_validation_lang.php */

EDIT: For you reference this is an override of the same language file in ./system/language/english/form_validation_lang.php

The manual does suggest you can change this file directly but if you do so and update your codeigniter core files in the future you could overwrite your changes. It's good practice to never amend files in your codeigniter system directory.
Codeigniter will always look for your language file in the application directory before it uses its own.

Just be aware that if a new rule appears in future codeigniter versions you'll need to add that to your override file.

Hope that helps Smile

Thanks Ayeyermaw Smile . It worked, awesome.

Theme © iAndrew 2016 - Forum software by © MyBB