我有一个 check_captcha 的回调函数,它查看是否$row
是==0
或== 1
(此信息是从 sql 中查询的)。
问题是我无法调用它,$self->form_validation->set_rule('captcha', 'call_back_check_captcha')
因为我的函数接受了一个$row
var。我现在调用它的方式是我收到无法访问错误消息。我怎样才能使这项工作?
function check_captcha( $row)
{
if($row ==0)//didnt find any
{
$this->form_validation->set_message('captcha', 'text dont match captcha');
return FALSE;
}
else
{
return TRUE;
}
}
function create_member()
{
$past = time() - 7200;
$this->db->query("DELETE FROM captcha WHERE captcha_time <".$past);
$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word =? AND ip_address =?";
$binds = array($_POST['captcha'], $this->input->ip_address(), $past);
$query= $this->db->query($sql, $binds);
$row = $query->row(); //row query rows : if it found an entry =1
$self->check_captcha($row->count);
//VALIDATIONS
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules( 'email_address', 'Email Address', 'trim|required|valid_email|unique[user.email_address]');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|unique[user.username]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_leng[32]');
$this->form_validation->set_rules('password2', 'Password Confirmation','trim|required|matches[password]');
if(!$_POST['captcha']){
$this->form_validation->set_rules('captcha', 'Captcha','trim|required');}else{
$this->form_validation->set_rules('captcha', 'Captcha', 'callback_check_captcha');}
if($this->form_validation->run()==FALSE)
{ //this -> to the curr obj(UserController) && registraion() points to the the function in controller
$this->registration(); //reloads reg page so they can fill out right stuff
}
else