mirza
mirza

Reputation: 5793

How to use codeigniter form validation library for two different languages at the same time?

I'm trying to use codeigniter form validation library for showing two different lines in two different languages at the same time but it throws an error:

$this -> form_validation -> set_message('required', 'Warning %s should not be empty! <br /> Dikkat %s alanı boş bırakılmamalıdır.');

Is there a way to using that function like this without facing that error:

A PHP Error was encountered

Severity: Warning

Message: sprintf(): Too few arguments

Filename: libraries/Form_validation.php

Line Number: 525

Upvotes: 0

Views: 596

Answers (1)

nielsstampe
nielsstampe

Reputation: 1364

The sprintf() function on line 525 in core/libraries/form_validation.php only has two arguments.

$message = sprintf($line, $this->_translate_fieldname($row['label']));

The first argument must be a string with designated insertion points. The following arguments (in a sprintf function) will have to match the number of insertion points. And codeigniter only uses one.

From the Codeigniter Userguide: http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html

If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.

But, the solution for your problem is this:

$this->form_validation->set_message('required', 'Warning %1$s should not be empty! <br /> Dikkat %1$s alanı boş bırakılmamalıdır.');

%1$s represents the first argument after the string argument in sprintf(). It is explained very well in the examples here: https://www.php.net/sprintf

Upvotes: 2

Related Questions