We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Validating object inside object

How I can validate an object from $this->request->getPost() that has inside other object? For example:

In AJAX data:
{ "something": { "value" : "someValue" } }

In server:
$validator->add("value", ...)


33.8k

I'm trying a workaround sending a JSON.stringify(...) instead of an Object of Objects, but the validator always success in the validation, even with very different values.



7.9k
edited Sep '14

Im afraid you have to create custom validation to validate your object

you can follow this guide to make your custome validation https://docs.phalcon.io/en/latest/reference/validation.html#validators



33.8k

I think I'll be using a string for that little thing (custom validator will be more work than).

THe problem is that I had discovered that everything I send to validate (for that object), even in a string form (1#a$2#b) returns true, no matter what the pattern is (and the vars are setted correctly).



33.8k

Well, I think this can't go worse.

It seems that Phalcon validates OK everything I send, no matter what. And I'm doing the validation the same as in the login, and there I don't have fails.