在HMVC CI中使用回调函数时收到表单验证错误...我对问题没什么了解...我的验证代码是-
$this->form_validation->set_rules('username', 'Email', 'trim|required|valid_email|callback_IsEmail_exist');
function IsEmail_exist() {
$existing_email = $this->db->where("email", $this->input->post('username'))->get('tbl_user')->num_rows();//p($existing_email);echo $this->db->last_query();die;
if ($existing_email != "0") {
$this->form_validation->set_message('email', 'Email ID already Exist.');
return false;
}
}
以下代码位于Custom_Form_validation.php中:
/* custom function by Pikachu */
class Custom_Form_validation extends CI_Form_validation {
public $CI;
function run($module = '', $group = '') {
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
以及在我的控制器中:
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library(array('Custom_Form_validation'));
$this->form_validation->CI =& $this;
$this->load->model('custom_model', 'custom');
}
在视图表单中仍然收到“需要电子邮件”错误消息。请帮助解决此问题。
答案 0 :(得分:1)
您好@pikachu而不是这样做-
Dashboard widget on Mac OS X export is no longer supported in Unity 5.4+.
将管道元素分成单独的参数,例如-
$this->form_validation->set_rules('username', 'Email', 'trim|required|valid_email|callback_IsEmail_exist');
这可能会对您有所帮助。