我正在处理用户注册表单。我试图使用户必须拥有一个尚未在系统中注册的电子邮件地址。
我认为is_unique
功能不起作用,因为所有电子邮件地址数据都以Base64编码格式存储,并且查询以未编码格式提交。
我尝试在我的控制器和模型中调整一些看起来合适的东西,但我最终会出错。
以下是 CONTROLLER:
中的功能function check_physician_email($physician_email){
$physician_email_check=$this->model_site->get_single_record( 'physicians', 'email', $physician_email );
if($physician_email_check){
$this->form_validation->set_message('check_physician_email', 'The %s is already taken!');
return FALSE;
}
else {
return TRUE;
}
}
使用此模型:
function get_single_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where($table_name, array( $primary_key_name => $primary_key_val));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_single_record
当这不起作用时,我开始将其指向get_email_record
并在我的模型中尝试了以下几种变体:
function get_email_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where('physicians', array( encode_decode($_REQUEST['email'], 'decode') => $primary_key_val));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_email_record
这只会导致 encode_decode error
:
Error Number: 1300
Invalid utf8 character string: '\xB2\xB6\xACr\x19\xDA\xB5\xB8\xA8r\x8A\xE9r\x89'
SELECT * FROM (`physicians`) WHERE `²¶¬rÚµ¸¨rŠér‰` = 'user@email.com'
Filename: /usr/sites/phototherapydoctor.com/www/html/models/model_site.php
Line Number: 92
如果我在 MODEL:
中执行此操作function get_email_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where('physicians', array( 'email' => encode_decode($_REQUEST[$primary_key_val],'encode')));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_email_record
我得到 Undefined index error
:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: user@email.com
Filename: models/model_site.php
Line Number: 92
答案 0 :(得分:0)
你没有设置我能看到的回调?您需要在表单验证规则中使用此功能。
$this->form_validation->set_rules('email','Email','callback_physician_email_check');