Welcome Guest, Not a member yet? Register   Sign In
How to make validation callback functions private?
#1

[eluser]rupin[/eluser]
The codeigniter documentation on validation rules suggests that we can build own callback functions for validations.
These functions reside in the controller class, and can be accessed directly when appropriate URL is formed.

I tried to add a'_' before the function name, but then codeigniter wont run the validation rule because the rule would become something like this

$rules['username'] = "required|min_length[5]|max_length[12]|callback__CheckUsernameExists";

instead of

$rules['username'] = "required|min_length[5]|max_length[12]|callback_CheckUsernameExists";

How do I make the CheckUsernameExists method private?
#2

[eluser]kaejiavo[/eluser]
[quote author="rupin" date="1287745955"]The codeigniter documentation on validation rules suggests that we can build own callback functions for validations.
These functions reside in the controller class, and can be accessed directly when appropriate URL is formed.

I tried to add a'_' before the function name, but then codeigniter wont run the validation rule because the rule would become something like this

$rules['username'] = "required|min_length[5]|max_length[12]|callback__CheckUsernameExists";

instead of

$rules['username'] = "required|min_length[5]|max_length[12]|callback_CheckUsernameExists";

How do I make the CheckUsernameExists method private?[/quote]

Hi rupin,

i am using the form validation exactly as in your first example and it works (using CI2.0)
Code:
$this->form_validation->set_rules('receiver_id', 'receiver_id', 'required|is_numeric|callback__receiver_check');
...

    function _receiver_check($receiver_id)
    { ... }

Marco
#3

[eluser]rupin[/eluser]
Thanks for you reply Marco..

I found that the problem wasnt in the function name, rather it was

$this->validation->set_message('_CheckUsernameExists', 'The Username already exists.Please select a different username');

I did not look at first argument;it should match the function name.

The message that I recieved 'Unable to access an error message corresponding to your field name.' made me realize my mistake...
#4

[eluser]Phil Sturgeon[/eluser]
Or use private / protected function?




Theme © iAndrew 2016 - Forum software by © MyBB