Welcome Guest, Not a member yet? Register   Sign In
Problem with lang: syntax in form_validation (SOLVED)
#1

[eluser]James Gifford[/eluser]
I am using the new form_validation library and I can't get the new shortcut syntax for field translations to work.

Here's what I'm trying to do:
Code:
$this->lang->load('login');
$this->load->library('form_validation');
$this->form_validation->set_rules(array(
   array('field' => 'username',    'label' => 'lang:username', 'rules' => 'required'),
   array('field' => 'password',    'label' => 'lang:password', 'rules' => 'required')));
if ($this->form_validation->run())
...

This results in the fields being named 'lang:username' and 'lang:password' respectively. If I replace the shorthand syntax with something like $this->lang->line('username') then it works just fine.

Is anyone else having problems with this aspect of the form_validation library? Or is there some setting or something that I missed?
#2

[eluser]James Gifford[/eluser]
Whoops! Nevermind.

I forgot I had modified the form_validation library to allow for outputting the label value in the form. I forgot to use the new _translate_fieldname() method that's all.
#3

[eluser]Aken[/eluser]
Written like that, the code assumes you want the literal string "lang:username".

I don't use the language things as of now, so I can't say for sure whether or not the shorthand property would work in the middle of the code. Try using lang:username without the quotes.

If that does work, load the language helper and and replace 'lang:username' with lang('username')
#4

[eluser]James Gifford[/eluser]
The new form_validation class allows for the shorthand notation (eg: lang:username) to be used when setting the rules. You have to have loaded the correct language file first, however.

What I forgot was that I had added a method to the class to output the value of the label within the form and this method wasn't using translation code which knows what to do with the shorthand notation.




Theme © iAndrew 2016 - Forum software by © MyBB