I have default values set on form inputs and the form submits because the onlt rule I need to apply in this case is trim|required
. How can I check if the submitted value is equal to the d开发者_StackOverflow中文版efault and display an error?
Thanks
Did you try doing it this way...
In your controller....
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;
}
}
More over here
精彩评论