Welcome Guest, Not a member yet? Register   Sign In
Handle Language / Validation Mode in the Form Validation Helper
#1

[eluser]dsentker[/eluser]
Hey Guys,

First: sorry for my bad english, i'm from germany and i hope my problem is understandable.

I am new at CodeIgniter cause I love the MVC Usage since i got unsolved (logical) problems with my "normal PHP knowledge". Be that as it may, here are my two little questions:

1: I'm interested in the handy Validation Helper - Sadly, i don't know how to handle different languages for that helper. I want to change the Error Messages (e.g. "The Password field is required!") into German - but how i can do that?

2: Validation Helper, too: I have the possibility to check, if a field matches another field. That's good - but what can i do if a field don't have to match with another field? In my case, the Password should NOT be the Username. In "standard PHP", i would use this:

Code:
$_POST['pass'] == $_POST['username'] ? echo 'Choose another password!' : echo 'success!';

Any possibility to use the Validation Helper for my wish?

Thanks for your Help!
#2

[eluser]flaky[/eluser]
Answers
1.
Quote:Translating Field Names

If you would like to store the "human" name you passed to the set_rules() function in a language file, and therefore make the name able to be translated, here's how:

First, prefix your "human" name with lang:, as in this example:
Code:
$this->form_validation->set_rules('first_name', 'lang:first_name', 'required');

Then, store the name in one of your language file arrays (without the prefix):
Code:
$lang['first_name'] = 'First Name';

Note: If you store your array item in a language file that is not loaded automatically by CI, you'll need to remember to load it in your controller using:
Code:
$this->lang->load('file_name');

See the Language Class page for more info regarding language files.
2.
use callback functions
example
Code:
$this->form_validation->set_rules('password', 'required|callback_check_with_username');
if ($this->form_validation->run() == TRUE){
.
.
.

public function check_with_username($password){
    $this->form_validation->set_message('check_with_username', 'Choose another password');
    
    if($password == $this->input->post('username'))
        return false;
    else
        return true;
}
#3

[eluser]dsentker[/eluser]
Thanks for your support.

To 1)
I think i was misunderstood. How can i change the Error Message, e.g. "The Password field is required" into "Es wird ein Passwort benötigt!" (German Version)? Do i have to read the Language class again? Sorry for my "noob" Questions... Sad

To 2)
Good Idea, thanks for that. Where i can learn more about callback functions and -triggers?
#4

[eluser]Johan André[/eluser]
[quote author="dsentker" date="1262055533"]Thanks for your support.

To 2)
Good Idea, thanks for that. Where i can learn more about callback functions and -triggers?[/quote]

Form validation class docs in userguide? Smile




Theme © iAndrew 2016 - Forum software by © MyBB