[eluser]Mike Chojnacki[/eluser]
[quote author="InsiteFX" date="1299877744"]Might work in a MY_Controller, but I have not tried it.
Give it a try and see if it will work.
InsiteFX[/quote]
Hi InsiteFX, thanks for your advice. It did try it, but it did not work straight away.
Here is the "fix" I applied.
applications/libraries/MY_Form_validation.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
function password_check($str)
{
var_dump($str);
$strlen = strlen($str);
if($strlen == 0)
{
return true;
}
elseif($strlen > 0 && $strlen < 8)
{
$this->set_message('password_check', 'The password has to be at least 8 characters in length.');
return false;
}
return true;
}
}
system/libraries/form_validation.php [start at line 589]
Code:
// MODIFIED
if ( ! method_exists($this->CI, $rule) && ! method_exists($this, $rule))
{
continue;
}
// Run the function and grab the result
if(method_exists($this, $rule))
{
$result = $this->$rule($postdata, $param);
}
elseif(method_exists($this->CI, $rule))
{
$result = $this->CI->$rule($postdata, $param);
}
// END MODIFIED
// ORIGINAL
if ( ! method_exists($this->CI, $rule))
{
continue;
}
// Run the function and grab the result
$result = $this->CI->$rule($postdata, $param);
// END ORIGINAL
Now, you can just add functions like "password_check" to MY_Form_validation and call them wherever you want, if no function is found it will fall back and check in the controller if that callback validation function exists there.
I just did it quickly now, does anyone have any input on as how to accomplish this effect without having to directly edit a system library file?
I really like this way much better cos I can have all my callbacks in one file and not clutter my controllers with them and reproduce code over several pages.