Welcome Guest, Not a member yet? Register   Sign In
validation class and callback functions.
#1

[eluser]nealumney[/eluser]
I have a callback function I want to call in a number of controllers, something like this:

Code:
function checkpostcode($postcode)
{
    $this->form_validation->set_message('postcode', 'The postcode you entered is not valid');
    return preg_match('^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$');
}
For some reason, if I place this in a 'helper' it does not work, but if it is created within the controller it works.

I call the helper before the validation rules are set thus:
Code:
$this->load->helper('checkpostcode');

And my validation rule array entry looks like this:

Code:
array('field'    => 'postcode','label'    => 'Postcode must be valid','rules'   => 'trim|required|callback_checkpostcode'),

Do validation callbacks have to sit within the controller? Or am I doing something wrong?

Thanks

Neal


Messages In This Thread
validation class and callback functions. - by El Forum - 05-25-2009, 07:25 AM
validation class and callback functions. - by El Forum - 05-25-2009, 07:30 AM
validation class and callback functions. - by El Forum - 05-25-2009, 07:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB