views:

92

answers:

1

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.

+2  A: 

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

For example:

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

wilmoore
http://framework.zend.com/manual/en/zend.filter.input.html
gawpertron
How would you use Zend_Filter_Input in conjuction with Zend_form?
gawpertron
Zend_Filter_Input looks like a striped down Zend_Form that purely handles Filters and Validators. It looks useful if you have a complex form with many decorators and complex validation rules. You could separate responsibility or provide alternative filter and validation, without breaking the base form. Cheers for the tip
gawpertron