How I can combine multiple form elements to one validator? I have address information which consists of
- Street address
- ZIP code
- Post office
If I add validator to each of them as streetValidator, zipCodeValidator, postOfficeValidator I end up with problem: There can be foostreet in somewhere (validation ok), 10101 somewhere (validation ok also) and barOffice in somewhere (validation ok too). But all address information combined, there's no address of "foostreet, 10101, barOffice".
Now you have:
<?php
$f = new Zend_Form();
$street = new Zend_Form_Element_Text('street');
$f->addElement($street);
$zip = new Zend_Form_Element_Text('zip');
$f->addElement($zip);
$office = new Zend_Form_Element_Text('office');
$f->addElement($office);
But it should be:
$f = new Zend_Form();
// All three fields are still seperated
$address = new My_Address_Fields();
$address->addValidator(new addressValidator());
$f->addElement($address);
Validator is something like
class addressValidator extends Zend_Validator_Abstract
{
public function isValid()
{
//$street = ???;
//$zip = ???;
//$office = ???;
// XMLRPC client which does the actual check
$v = new checkAddress($street, $zip, $office);
return (bool)$v->isValid();
}
}