Welcome Guest, Not a member yet? Register   Sign In
Form Validation Callbacks Load From External Source
#1

[eluser]skunkbad[/eluser]
I've got more than one controller that calls some of the identical callback functions to validate form data using the CI Form Validation class. I'm wondering what I can do to get them out of the controller, and into a centralized form validation callback library, plugin, helper, or whatever. The docs don't mention loading the callbacks from an external source, and I'd be happy if it is possible. What are other people doing to make this happen?

Right now I'm trying to test loading one of the callback functions from the controllers constructor. So, for instance:

Code:
function Administration()
{
    parent::Controller();
    $this->load->plugin('usernamecheckoff');
}

Then, elsewhere in the controller, when I'm trying to use the function as a callback for form validation:

Code:
$this->form_validation->set_rules('uname', 'USERNAME' , 'trim|required|max_length[12]|callback_usernamecheckoff');

and then I have the actual plugin, appropriately placed in system/application/plugins/ and named usernamecheckoff_pi.php:

Code:
<?php
function usernamecheckoff($uname){
    if($uname != 'billythekid'){
        $this->form_validation->set_message('usernamecheckoff', 'Supplied <span class="redfield">%s</span> was not billythekid.');
        return FALSE;
    }else{
        return $uname;
    }
}

But this isn't working. If for instance, in my form I use a name other than 'billythekid', the form validation error message is not displayed.


Messages In This Thread
Form Validation Callbacks Load From External Source - by El Forum - 08-03-2009, 09:20 PM
Form Validation Callbacks Load From External Source - by El Forum - 08-04-2009, 01:18 AM
Form Validation Callbacks Load From External Source - by El Forum - 08-04-2009, 01:22 AM
Form Validation Callbacks Load From External Source - by El Forum - 04-06-2011, 06:28 PM
Form Validation Callbacks Load From External Source - by El Forum - 04-07-2011, 02:04 AM
Form Validation Callbacks Load From External Source - by El Forum - 04-07-2011, 04:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB