How to make a custom validator to validate fields against each other in Phalcon 4 #15391
Unanswered
Krzysiaczek
asked this question in
Q&A
Replies: 1 comment
-
You can add custom validation to a form by creating a new custom Validator class, then adding it to an instance of a Phalcon form field class, then adding that class to the form. If you're coding the form by hand (ie: not using Phalcon's form field classes), then I don't think there's any way to automatically include validation. You'll have to simply access the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there
I am trying to create a custom validator to additionally verify the data coming from the form fields against each other and the DB e.g.
After a standard validation, I'd like to check (somehow - in a custom validator) if user_id belongs (works) for business_id and have the right to delete records at all, and if the record_id actually belongs to business_id as well.
I can't find any information about creating a custom validator other than here https://docs.phalcon.io/4.0/en/validation#custom-validators
Unfortunately, this documentation doesn't explain how to pass multiple fields from the form.
Also when I try to initiate a separate object by calling a
new Validator()
inside the Form->initialize() method this validator object seems to be totally ignored by$form->isValid()
check in the controller.Also using the validation sometimes in the context of the Model and other time in the context of validation of Form is quite confusing
Any advice help or guidance?
Update:
I found a similar problem by the end of this thread in the old forum: https://forum.phalcon.io/discussion/3123/custom-date-validator
Let's say we want to compare Start Date vs Finish Date to be sure that Finish Date would be greater than Start Date field. It looks like the same problem. That validation is focused on the validation of a single field. Am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions