Welcome Guest, Not a member yet? Register   Sign In
Form Validation Library - callback implementation flaw
#1

The Codeigniter Form Verification library allows creating custom "callback" rules implemented in functions as described in the Documentation.

It seems to me that there is a flaw in how it is implemented. It appears that the callback function must be a method of the main CodeIgniter object:

https://github.com/bcit-ci/CodeIgniter/b...n.php#L715

PHP Code:
// Call the function that corresponds to the rule
if ($callback OR $callable !== FALSE)
{
 if (
$callback)
 {
 if ( ! 
method_exists($this->CI$rule)) // <---- CHECK IS DONE HERE
 
{
 
log_message('debug''Unable to find callback validation rule: '.$rule);
 
$result FALSE;
 }
 else
 {
 
// Run the function and grab the result
 
$result $this->CI->$rule($postdata$param);
 }
 }

... 

It forces the callback function to be public method of the controller. The callback can't be part of a helper or a library, because nor helper nor library derive from CodeIgniter main object.

Because the callback is a public method of the controller it can be called directly. In case of the example in documentation accessing
Code:
https://example.org/example_app/form/username_check/test
will run the code in that callback function, which is not meant to be called directly.

Isn't it a design flaw or am I missing something?
Reply
#2

You can prepend it with _ to hide it from the automatic url resolver. Have only tried to load it locally within the same class, so can't comment of the rest.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB