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
?>