[eluser]Flemming[/eluser]
Hi guys, I hope you can help me with this as it has got me really puzzled...
I'm working on a multi lingual site. The user's current language is stored in session and then from my controllers I load generic views which are full of
Code:
echo lang('lang_token_name')
so that 1 view can serve an unlimited amount of languages.
All fine so far!
I'm doing client side validation on my forms and have the js error messages populated using the
Code:
echo lang('lang_token_name')
method ... again - all fine so far!
But I would like to do server side validation too. I can do it in English OK because my form fields have English names. Of course, I need the form fields to be english names so that I don't have to rewrite my controllers for database inserts after forms are submitted (e.g. $this->input->post('name') gets inserted into DB regardless of what language the form is displayed in.
Now comes the problem - even if I use a french form validation lang file, the error messages generated by CI will be along the lines of:
Code:
Le champ Name est requis.
where 'Name' is the ...
Ahhhhhhhhhhhh ... I just figured it out!
Instead of doing:
Code:
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
I can do:
Code:
$this->form_validation->set_rules('name', lang('name'), 'trim|required|xss_clean');
which SHOULD generate an error like:
Code:
Le champ Nom est requis.
I had to type the question up in order to realise the solution! hehe
Ah well ... maybe it will be useful to someone else - or maybe it won't even work!