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

(This post was last modified: 01-30-2017, 11:47 AM by PaulD. Edit Reason: Added final note )

Hi,

I would put the model call into a callback, something like this:

PHP Code:
$this->form_validation->set_rules'email''Email Address''trim|required|valid_email|callback_permission_check'); 

And your callback function in your controller would look something like:
PHP Code:
private function permission_check() {
 
    // load your model
 
    $this->load->model('usermodel');
 
    
     
// set error message
 
    $this->form_validation->set_message'permission_check''This user already has access.' );
 
    
     
// get your variables
 
    $email $this->input->post('email'TRUE);
 
    $user_id = ? // not sure how you are getting this but you cannot pass it in the function call
 
    
     
// do the check
 
    if($this->usermodel->permission_exists($email$user_id)) return TRUE;

 
    return FALSE;


In that way you can still set an error message. I read you link and have never used that method, so sorry if the above suggestion is a bit off topic.
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