0

Is it possible to add 2 or more custom validation functions using the same field?

$this->form_validation->set_rules('myfield', 'My Field','required|my_method1|my_method2');

eg. my_method1 check the string format and my_method2 check the existence of the string in my database.

Seems like just the first method works and the second one is ignored. Is it because i'm using the same parameter for both functions?

thanks.

2
  • Can we see the two methods you are using for validation? Commented Apr 14, 2015 at 19:20
  • please put your functions. Commented Apr 14, 2015 at 20:41

1 Answer 1

0

You can!

In each my_method_N($x) function, you must inform them as prefix the name callback_, for instance: callback_my_function1|callback_my_function2.

Take a look at this question that explains how you can use multiple callback functions and the syntax in the manual.

Codeigniter form validation multiple callbacks

http://www.codeigniter.com/user_guide/libraries/form_validation.html?highlight=form_validation#callbacks-your-own-validation-methods

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

Comments

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.