5

Using CakePHP 1.3

I understand the example at http://book.cakephp.org/complete/1143/Data-Validation#Adding-your-own-Validation-Methods-1181 on how to add my own validation methods, but maybe I'm missing something.

I only want to validate that Field_B is 'numeric' (a core validation) if Field_A (a select/option) is equal to a certain value.

It seems that I'm supposed to add a custom validation, and then I check the values of other fields with $this->data, but how do I call on a built-in validation from within a custom validation function? Or am I doing it wrong?

1 Answer 1

4

Validation::numeric($this->data['field'])

Validation class (validation.php) is located in cake/cake/libs and you can see the available methods by inspecting the file (they're the same as the ones you pass to the validation array).

Validation methods return true if validation passes.

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

2 Comments

So, is Validation available in the model scope, or do I need to include it before using it?
Validation is imported whenever the Model base class file is included so it will always be available in any of your models. You can call the method statically, or get an instance $val = Validation::getInstance(); $val->numeric($this->data['field']);

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.