views:

34

answers:

1

Hi,

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 default and display an error?

Thanks

+2  A: 

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

ShiVik
I put an error message for validation->run() == FALSE. Now I keep getting the error. Seems the validation is not running and even when the value is not left to the default, it still does not validate
pixeltocode