Validate a field inside a fieldset using the form context

Consider a form MyForm, containing a fieldset MyFieldset, containing a field MyField.

I’m writing a custom validator for MyField and I need to access the value of another field in the form which is not in the same fieldset.

In the isValid method of the validator I have access to the $context object, which seems to contain the values of the other fields in the same fieldset.

Is there a way to access the values of other fields of the form, not in the same fieldset?

I’m using zendframework/zendframework version 2.4.12

One way is to add additional field on higher level of form (where fieldset is added) and attach validator there. Context always get raw data from nested fields, but not from parents.

That could be a solution.

Still, I guess that in this way the error messages would apper near to the new field and not near the one that I am actually validating.

It’k kind onf ugly, but for the moment I solved it injecting the request in the validator and retrieving the other fields value directly from there