开发者

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

开发者 https://www.devze.com 2023-01-12 22:23 出处:网络
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开发者_StackO

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

精彩评论

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