Welcome Guest, Not a member yet? Register   Sign In
Validating/comparing min and max values using validation library
#1

[eluser]Bikun[/eluser]
I need to check if max_chars is bigger then min_chars. How could I do that with validation library?

Here is what I have in my controller:
$rules['min_chars'] = "required|integer";
$rules['max_chars'] = "required|integer";

If I'm not mistaken, I can't create a function with 2 parameters and use it in the rule.
#2

[eluser]Michael Wales[/eluser]
Code:
$this->load->library('common_sense');
if ($this->common_sense->check_logic() === FALSE) {
  die();
}

I fail to see the reason to include a validation rule to make sure these configuration settings are logical. Validation is there to aid the client, the user of your site, not inept developers.
#3

[eluser]helmutbjorg[/eluser]
Michael... I think you may have taken Bikun's post too literally? I think min_chars/max_chars are the names of his fields. Like if you were to check if from_date is greater than to_date. In that case you would use a callback function.

Bikun check the userguide on creating a callback validation function.
#4

[eluser]Michael Wales[/eluser]
Ah! Thanks for pointing that out helmut - I apologize profusely Bikun.

You can use the Input class to refer to a different field within the callback.




Theme © iAndrew 2016 - Forum software by © MyBB