0
配置/ login_rules.php如何通过定制回调)3个参数( - 笨
这里的回调函数check_email_existence
我想传递三个参数,这些参数(电子邮件,表,字段)
<?php
/**
* SETTING VALIDATION RULES FOR THE LOGIN FORM
*/
$config['login_settings'] = array(
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required|trim|min_length[6]|max_length[20]|xss_clean',
'errors' => array(
'required' => 'You must provide a %s.',
),
),
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'required|trim|valid_email|xss_clean|check_email_existence'
)
);
?>
我已经扩展了表单验证辅助库/ MY_Form_validation.php
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
protected $CI;
public function __construct($config = array())
{
parent::__construct($config);
$this->CI =& get_instance();
}
function check_email_existence($email,$table,$field) {
$this->CI->form_validation->set_message('check_email_existence', 'This %s id is not registered.');
$query = $this->CI->db->query("SELECT COUNT(*) AS count FROM $table WHERE $field = '".$email."' ");
$row = $query->row();
return ($row->count > 0) ? 'success' : 'failure';
}
}//class
?>