CodeIgniter Forums
Form Error : Remove 'The' Word from Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form Error : Remove 'The' Word from Error (/showthread.php?tid=51736)



Form Error : Remove 'The' Word from Error - El Forum - 05-15-2012

[eluser]npCoda[/eluser]
Hello!
I am beginner to Code Igniter. Recently I am working in form validation. I am using form validation error to check the error.

Code:
$this->load->library('form_validation');
    
     $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)
  {
  $this->session->set_flashdata(array('error_message'=>validation_errors()));
   redirect($this->session->userdata('current_url'),'refresh');
  }


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.





Form Error : Remove 'The' Word from Error - El Forum - 05-15-2012

[eluser]Aken[/eluser]
Check the set_message() method in the Form Validation library documentation.


Form Error : Remove 'The' Word from Error - El Forum - 05-15-2012

[eluser]weboap[/eluser]
check http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors
section

Setting Error Messages


Form Error : Remove 'The' Word from Error - El Forum - 05-16-2012

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


Form Error : Remove 'The' Word from Error - El Forum - 05-16-2012

[eluser]Sanjay Sarvaiya[/eluser]
You can do with this.
Code:
$this->load->library('form_validation');
    
   $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) {    
     if(isset($this->form_validation->_error_array['user_full_name']))
      echo 'name requierd';
     else if(isset($this->form_validation->_error_array['user_email']))
      echo 'email required';
    }



Form Error : Remove 'The' Word from Error - El Forum - 05-16-2012

[eluser]Ayeyermaw[/eluser]
Create a language folder in your application directory and create the following file:

application/language/english/form_validation_lang.php

then place the following in that file:

Code:
<?php

$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



Form Error : Remove 'The' Word from Error - El Forum - 05-24-2012

[eluser]npCoda[/eluser]
Thanks Ayeyermaw Smile . It worked, awesome.