Welcome Guest, Not a member yet? Register   Sign In
Preventing custom form validation function from being accessed via a URL
#1

(This post was last modified: 05-04-2016, 03:32 AM by CINewb.)

When you create a custom validation rule within a controller, it is accessible via the browser, which in most cases you wouldn't want.  You can't make the callback function private, it seems CI needs it to be public.

I've therefore reverted to this:


PHP Code:
$this->form_validation->set_message('_my_custom_rule''Your input failed the custom rule');
$this->form_validation->set_rules('email''Email''callback__my_custom_rule' );

public function 
_my_custom_rule$value ) {
    // Do something here and return true or false



The underscore at the front of the function name prevents it being called via the browser.  However, it doesn't seem as elegant using an underscore in the set_message() and set_rules() methods.

I know this is pedantic, but is this the best way?  On Stackoverflow I did see an answer which involved creating a new class/library which extends the CI Validation class, but this seemed like an overkill.

Thanks
Reply


Messages In This Thread
Preventing custom form validation function from being accessed via a URL - by CINewb - 05-04-2016, 03:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB