简体   繁体   English

Codeigniter自定义form_validation

[英]Codeigniter custom form_validation

I have a added custom function to the system->libraries->Form_validation.php 我在system-> libraries-> Form_validation.php中添加了一个自定义函数


public function serial_exist($str, $value)
{

    list($table, $column) = explode('.', $value, 2);
    $query = $this->CI->db->query("SELECT COUNT(*) AS count FROM $table WHERE $column = '$str'");
    $row = $query->row();

    if ($row->count > 0) {
        $query = $this->CI->db->query("SELECT COUNT(*) AS count FROM v_redeem WHERE v_serial='$str'");
        $row = $query->row();
        if ($row->count > 0) {
            /// used
            return FALSE;
        } else {
            return TRUE;
        }
    } else {
        //invalid serial
        return FALSE;
    }
}

The I call the function from the below. 我从下面调用该函数。

$this->form_validation->set_rules('serial','serial','required|xss_clean|serial_exist[v_info.v_serial]');

This works just fine but my issue how can I get the to different MSG say'n either invalid or used serial? 这工作得很好,但是我的问题是如何获得不同的味精,说不是无效序列还是已使用序列?

Hope my question is clear. 希望我的问题清楚。

Try to set a custom set_message. 尝试设置自定义set_message。 like this--- 像这样 - -

$this->form_validation->set_message('serial_exist', 'Your custom Message.');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM