2

I'm trying to pass two values to a function, so that i can check the username and password for the users. However, i can't get it to work. When i have one value, there is ne problem doing this. But how can i pass more than one value?

function($val1, $val2)

This is my code http://pastebin.com/JKnTEqLN

3 Answers 3

3

If you want to pass two variables to your function, change line 6

$this->form_validation->set_rules('username', 'Username', 'required|alpha|xss_clean|callback__check_login');

to

$this->form_validation->set_rules('username', 'Username', 'required|alpha|xss_clean|callback__check_login[$val1,$val2]');

For more than two values, youll need to use http_build_query($val2) and then explode it inside of your function

Sign up to request clarification or add additional context in comments.

Comments

1

(please correct me if I didn't get the question right:)

I wouldn't do that way.

Instead of using the _check_login() function callback as a validator for the username field (which doesn't really make sense, imho), why not call the check_login($username,$password) function WHEN the input fields are validated?

So

  if($this->form_validation->run() == FALSE)
  {
   $this->load->view('user_login');
  }
  else
  {
    $this->user_model->check_login();
  }

In User model you will be doing the check

Anyway, that's what the form_validation library is for, to validate inputs, not to elaborate datas.

If you just wanna check the existence of a user (to avoid duplicates, for example) to validate the input field, then you don't need the $password parameter, so the callback would work just fine.

2 Comments

well, if i do it that way, i don't get any error messages from the validation_errors() do i? so, thats a bit weird i think..
hm, did it another way around. So, thanks for the handsup anyway m8.
0

public function score_check($name, $arr) {If you would like to pass two variables I have found the best way to create an array with both variables.

$arr = array($val1, $val2);
$this->form_validation->set_rules('username', 'Username', 'required|alpha|xss_clean|callback__check_login['.$arr.']');

Your callback would be something like

public function check_login($str, $arr) {
      $val1  = $arr[0];
      $val2 = $arr[1];
}

Hope that helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.