Welcome Guest, Not a member yet? Register   Sign In
Form Validation "ignores" false results of custom functions placed in helper
#1

[eluser]Xelgen[/eluser]
Hello, stuck on this for hours, read the manual word-by-word but didn't understand the reasons.

So, I'm using custom functions for Form Validations in CI 1.7.0 .
When the function is in controller file, everything works perfect.
But as I have lot of functions being used in lot of different places, I wanted to place them all in helper file, let's say my_validation_helper.php

The weird things start here.

First of all I found out, that in this case you shouldn't use "callback_" prefix in rule. As if you do so, the fucntion will not be found and called. After looking through validation class source it looks reasonable.
When you place just function name in rules, it is being called, and processed.

BUT it looks like, Validation Class just "doesn't care" of what did function return.

Helper:
Code:
//* My validation helper file
<?php
function always_false($a)
    {        
        echo 'I\'m Always False'; //See if it is being called
        return FALSE;    
    }

My validation config:
Code:
$config = array(
                 'reciept' => array(
                                    array(
                                            'field' => 'reciept_number',
                                            'label' => 'Reciept Number',
                                            'rules' => 'trim|required|is_natural|exact_length[8]|always_false'
                                          
                                         ),
                                     ),
               );

My Controller:
Code:
function index()
    {        
        $this->load->library('form_validation');
        $this->load->helper('my_verification');    
        
            
        
        if ($this->form_validation->run('reciept') === FALSE)
        {
               $this->load->view('add');              
        }
        else
        {

               // SKIPPED - Processing data, and passing it to model
        
               $this->load->view('add_success', $data);
        }
}

So when I enter 8 digit number, in field, I should get a validation error, with "Unable to access an error message corresponding to your field name." error message, right? Instead validation is being considered as successfully passed, and controller sends data to the model. (yes, with "I'm always false" being echoed)

What can be the reason? And how to solve that?
Will do really appreciate any ideas.

P.S. Functions are working properly when called from controller. So helper loading and it's functions do work.

P.P.S. It's same if I write let's say php's is_bool function - string successfuly validates as "boolean".


Messages In This Thread
Form Validation "ignores" false results of custom functions placed in helper - by El Forum - 01-15-2009, 08:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB