Codeigniter callback function with multiple parameters during form validation

In Codeigniter:

Here is the callback function that I use to check:

public function has_match($password, $username){
    if (0) {
        // user exists
        return true;
    }
    else {
        $this->form_validation->set_message('has_match', 'Invalid Username/password entered ' . $password . ' ' . $username);
        return false;
    }
}

The following are validation rules:

$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|callback_has_match[username]');

Can someone please tell me what I am doing wrong here by calling the callback function, since I cannot get the value of the username field and it continues to show the "username" (inside the $ username variable in the callback)

+4
source share
3 answers

. callback has_match _ . , , :

callback_has_match[$username]

, has_match(), $username. , . , , , , , min_length [10] - PHP. , , :

$this->form_validation->set_rules('password', 'Password', 'required|callback_has_match[' . $username . ']');

, , , .

, , , , - , . / ?

, , . , /, , , , - .

:

$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|callback_has_match[username]');

if ($this->form_validation->run() != FALSE) {
    $validLogin = $this->muser->checkLogin($username, $password);

    if ($validLogin) {
        //Username/password combo exists in DB, save in session or whatever.
    } else {
        //Username/password combo does not exist in DB, show an error.
    }
} else {
    //Code for when form fields have not been provided correctly.
}
+7

public function has_match(){
    if (0) {
        // user exists
        return true;
    }
    else {

        $password   =   $this->input->post('password');
        $username   =   $this->input->post('username');

        $this->form_validation->set_message('has_match', 'Invalid Username/password entered ' . $password . ' ' . $username);
        return false;
    }
}
+1

//CALLBACKS

public function check_user () {

    $result = FALSE;

    $username=$this->input->post('username');

    $email=$this->input->post('emailad');

    $dbmember=$this->members->get_members();

    foreach ( $dbmember as $key){

        // condition of username and email  
        if($username==$key && $email==$key){

        if($username == $key->UserName && $email == $key->EmailAddress){
              $this->form_validation->set_message('check_user','already existed!
                      Please check username and email agian.');
              return FALSE;
              break;
            }                

        return TRUE;

        }  
    }
0
source

All Articles