开发者

Codeigniter - form validation check for default value in <input>

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜