2016-11-28 134 views
0

我在下面有下面的代码。我的问题是它只触发回调。 required和valid_email规则不会被调用。我期望按顺序执行规则。但是当我删除回调它运行正常。 TIA。Codeigniter表单验证回调问题

$this->form_validation->set_rules('search_word', 'Email address', 'trim|required|valid_email|callback_has_valid_credentials'); 

$this->form_validation->set_message('has_valid_credentials', '{field} is not registered in the system.'); 

if ($this->form_validation->run() == FALSE){ 

    $this->load->view('login/reset'); 
    return; 
    } 
+0

您是否定义了一个名为has_valid_credentials的函数? –

+0

请尝试[this](http://stackoverflow.com/a/40836772/6054930);) – ShutUpMagda

+0

@ErolKESKİN是的,我有函数名为has_valid_credentials。我尝试了前缀'callback_has_valid_credentials',并通过数据库进行搜索。我也尝试没有** callback_前缀**和必需和valid_email都工作,但回调不是。这是一个错误吗? – Tooteet

回答

1

您没有一个名为has_valid_credentials定义的函数。

public function has_valid_credentials($str) { 
    /** Write validation code here **/ 
} 

供您参考,请查阅文档。

https://www.codeigniter.com/userguide3/libraries/form_validation.html#callbacks-your-own-validation-methods

+0

对不起。我没有包含has_valid_credentials函数代码,但我有。我只是指出这个问题,即每当我包含回调时,其他两个规则都不会被触发,只有回调。 – Tooteet