phpkohana-2

pre_filter() in Kohana 2.x not working as expected


As of Kohana 2.x documentation,pre_filter() will execute before validation of input fields but its not working as of expected.

I'm trying to trim input values entered by user before validation as,

$post = Validation::factory($_POST);
$post->pre_filter('trim');

If try to view the input value entered by user as,

echo 'a'.$post->name.'b'; // to observe white spaces appended alphabets 

echo's a john b,actually it should be ajohnb means still white spaces exists. What might the wrong in this ?


Solution

  • You should do:

    $post = Validation::factory($_POST);
    $post->pre_filter('trim');
    $post->validate();
    

    Only when you call validate() pre filters are applied.

    http://docs.kohanaphp.com/libraries/validation