On Fri, Sep 26, 2008 at 8:52 AM, Ian R <[EMAIL PROTECTED]> wrote:

>
> ...For example, say I wanted to get contact information: either a phone
> number, an email address, or both, but NOT neither.
>
> I'm about to create a custom validator but I'm wondering if such a thing
> already exists.  I can't seem to find anything through my various searches
> but I'm not entirely sure what to call that.
>
> I'm just now picking up speed with ZF, it's just starting to click.  It's
> very exciting!
>
> Ian
>

Maybe someone else will correct me, but I think one way to do this is indeed
to write your own validator. When you add the validator you might say
something like

'multi_fields'=>array(
        new My_Validator_OneOrMoreFields(),
        'fields'=>array('phone','email'),
        'messages'=>array("Please provide either a phone number or an email
address')
            ),

And in your validator's logic you check that either one or the other is
nonempty. Meanwhile you can also add the validators e.,g., on the email,
that ship with ZF, with the allowEmpty flag set to true.

I did this for one form, and found I could use it again for another, giving
me a pleasing sense of DRY satisfaction.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness

Reply via email to