1

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

1
  • @pixeltocide - can you show a snippet of html form you have created? Commented Aug 20, 2010 at 10:53

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.