2010-08-20 57 views
1

默认值的表单验证检查我有表单输入上设置的默认值和表单提交,因为我需要适用的onlt规则是trim|required。如何检查提交的值是否等于默认值并显示错误?Codeigniter - 在<input><input>

感谢

+0

@pixeltocide - 你可以展现您创建的html表单片段? – vikmalhotra 2010-08-20 10:53:22

回答

3

你尝试做这种方式...

在你的控制器....

function index() { 
    $this->load->helper(array('form', 'url')); 
    $this->load->library('validation'); 

    $rules['sometext'] = "trim|required|callback_sometext_check"; 

    $this->validation->set_rules($rules); 

    if ($this->validation->run() == FALSE) { 
    $this->load->view('myform'); 
    } else { 
    $this->load->view('formsuccess'); 
    } 
} 

function sometext_check($str) { 
    if ($str == "default") { 
    $this->validation->set_message('sometext_check', 'The %s field should be "default"'); 
    return FALSE; 
    } else { 
    return TRUE; 
    } 
} 

更多了here

+0

我把验证的错误信息 - > run()== FALSE。现在我不断收到错误。似乎验证没有运行,即使该值没有保留到默认值,它仍然不验证 – pixeltocode 2010-08-21 09:01:25

相关问题