Welcome Guest, Not a member yet? Register   Sign In
Anonymous function Validation
#5

In case anyone else wants to do this or runs into a similar issue, I found a solution to the problem which is not ideal, but will work. Turns out, you can't directly call another function in another class in the form checker otherwise it has no idea what library is being use for returning the data, but what you can do is put in an anonymous function, then with in that call a separate function to do whatever you want and return that. Basically, I changed the following and now it works the way I want it to:


PHP Code:
$this->load->library( 'form_validation' );
$this->load->helper( 'form' );

$this->form_validation->set_rules( 'email', 'Email Address', [ 'trim', 'required', 'valid_email', [ 'permission_exists', $this->Usermodel->permission_exists( $this->input->post( 'email' ), $user['id'] ) ] ] );  

to this:


PHP Code:
$this->user_id $user['id'];
$this->load->library'form_validation' );
$this->load->helper'form' );

$this->form_validation->set_rules'email''Email Address', [ 'trim''required''valid_email', [ 'permission_exists', function ( $email ){ return $this->Usermodel->permission_exists$email$this->user_id ); } ] ] ); 

I kept everything in the permission_exists function exactly the same.

Would be cool if codeigniter could add something like I was wanting to do directly as it could make form validation a lot more powerful.
Reply


Messages In This Thread
Anonymous function Validation - by burgoyn1 - 01-29-2017, 10:00 PM
RE: Anonymous function Validation - by PaulD - 01-30-2017, 11:40 AM
RE: Anonymous function Validation - by burgoyn1 - 01-30-2017, 01:45 PM
RE: Anonymous function Validation - by PaulD - 01-30-2017, 02:01 PM
RE: Anonymous function Validation - by burgoyn1 - 01-31-2017, 04:37 AM
RE: Anonymous function Validation - by shernandez - 06-12-2017, 06:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB