Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter is_unique Error Message in Language File

When using CodeIgniter I like to set my error messages in application/language/english/form_validation_lang.php which works fine for every error message but does not seem to work for the is_unique message as it gives me the standard message of "The email field must contain a unique value."

My code:

$lang['is_unique'] = "The %s entered is already in use.";

like image 222
James Walker Avatar asked May 29 '15 11:05

James Walker


People also ask

How do I display error messages in other languages in CodeIgniter?

In your CodeIgniter system folder you'll find one called language containing sets of language files. You can create your own language files as needed in order to display error and other messages in other languages. Language files are typically stored in your system/language directory.

What is CodeIgniter form validation?

CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you’ll write. Try it! Before explaining CodeIgniter’s approach to data validation, let’s describe the ideal scenario: A form is displayed. You fill it in and submit it.

What is Codeigniter 4 language localization?

Inside this article we will see the concept of CodeIgniter 4 Language Localization. Simply means creating a site in CodeIgniter 4 but in different different language. This article will be very interesting to learn and easy to implement in your code. Let’s get started – CodeIgniter 4 Website in Multi Language.

How to use environment variables in Codeigniter 4?

When we install CodeIgniter 4, we will have env file at root. To use the environment variables means using variables at global scope we need to do env to .env Either we can do via renaming file as simple as that. Also we can do by terminal command. Above command will create a copy of env file to .env file.


1 Answers

Create a file called form_validation_lang.php in so like below

  • application/language/english/form_validation_lang.php

Go to system/language/english/form_validation_lang.php find.

$lang['form_validation_is_unique'] = 'The {field} field must contain a unique value.';

Copy Key Above Then Add Into application/language/english/form_validation_lang.php

$lang['form_validation_is_unique'] = 'The {field} entered is already in use.';

Next

On Controller Form Validation Add

$this->lang->load('form_validation', 'english');

Like

$this->lang->load('form_validation', 'english');
$this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[users.username]');

Note: If you use the form_validation is_unique in other controllers and want to use that message you will need to load this $this->lang->load('form_validation', 'english'); On to that controller as well unless you choose to autoload it.

like image 186
Mr. ED Avatar answered Sep 22 '22 10:09

Mr. ED