Consulte la 'Nota: Contexto de validación' en este page. Zend_Form pasa el contexto a lo largo de cada llamada Zend_Form_Element :: isValid como el segundo parámetro. Así que simplemente escriba su propio validador que analiza el contexto.
EDIT:
bien, pensé I'ld tomar un tiro en esto por mí mismo. No está probado, ni es un medio para todos los fines, pero te dará una idea básica.
class My_Validator_OneFieldShouldBePresent extend Zend_Validator_Abstract
{
const NOT_PRESENT = 'notPresent';
protected $_messageTemplates = array(
self::NOT_PRESENT => 'Field %field% is not present'
);
protected $_messageVariables = array(
'field' => '_field'
);
protected $_field;
protected $_listOfFields;
public function __construct(array $listOfFields)
{
$this->_listOfFields = $listOfFields;
}
public function isValid($value, $context = null)
{
if(!is_array($context))
{
$this->_error(self::NOT_PRESENT);
return false;
}
foreach($this->_listOfFields as $field)
{
if(isset($context[ $field ]))
{
return true;
}
}
$this->_field = $field;
$this->_error(self::NOT_PRESENT);
return false;
}
}
Uso:
$oneOfTheseFieldsShouldBePresent = array('companyname', 'companyother');
$companyname = new Zend_Form_Element_Text('companyname');
$companyname->setLabel('Company Name');
$companyname->setDecorators($decors);
$companyname->addValidator(new My_Validator_OneFieldShouldBePresent($oneOfTheseFieldsShouldBePresent));
$this->addElement($companyname);
$companyother = new Zend_Form_Element_Text('companyother');
$companyother->setLabel('Company Other');
$companyother->setDecorators($decors);
$companyname->addValidator(new My_Validator_OneFieldShouldBePresent($oneOfTheseFieldsShouldBePresent));
$this->addElement($companyother);