2
votes

I've split up a Form into 3 SubForms and for one of the elements, in the last SubForm, I am creating a Validator that extends Zend_Validator_Abstract.

This validator needs to check that a value, on the second SubForm, is not empty. However this value will not be in the $context array for the element in the Third SubForm.

What is a sensible way of making this value available in the $context across SubForms?

...

After some thought, the only way I can think of doing this is to pass a reference of the parent Form to the Validator's constructor despite it breaking encapsulation.

1

1 Answers

3
votes

You might also try overriding the form object isValid() method and utilizing the $data variable that is available there.

For example:

<?php 
class MyForm extends Zend_Form {
    public function isValid($data) {
        // check $data['fieldname'] or add a new validator here, then...
        return parent::isValid($data);
    }
}