The example was in my first email:
$this->setValidator('mpn', new sfValidatorAnd(array(
new sfValidatorString(array('min_length' => 5, 'max_length' => 64,
'required' => false)),
new sfValidatorRegex(array('pattern' =>
'/^(\s+)?[\w-\#\/]+(\s+)?$/', 'required' => false))
)));
If the field is empry, I want the complex sfValidatorAnd to pass and
if the field has data, I want it to be validated by both the string
validator and the regex validator.
On Thu, Nov 27, 2008 at 9:14 PM, Daum <[EMAIL PROTECTED]> wrote:
>
> I don't think I quite completely understand what you mean about the &&
> interpretation in PHP. PHP interprets && as far as I know like almost
> all other languages, it short circuits if the first condition is false
> (to improve performance as you need not then check the second
> parameter).
>
> What do you also mean that it needs to pass both validators but
> respect the 'required' option? It does, if you make one required and
> the other not, it will require the field to be filled in, which will
> also then require the other one to validate.
>
> Could you give me an example of what you are trying to achieve here?
> Daum
>
> On Nov 27, 7:45 am, Kiril Angov <[EMAIL PROTECTED]> wrote:
>> The thing is that it needs to pass both validators but also for those
>> validators to respect the not required option. This is the way php
>> checks the && operator, I mean one side of the && does not care about
>> the other side. They also do not care if they are used with && or
>> simply with an if statement.
>>
>> Sent from my iPhone
>>
>> On Nov 27, 2008, at 6:27, Daum <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>
>> > Hi Kiril -
>> > The validators are actually being affected by the 'required'=>false,
>> > you should be able to post a blank field to your form and it will
>> > validate(I just verified this). The reason when you put any text in
>> > the field both validators are activated is because they are both
>> > activated(as the field is filled in, therefore must pass both
>> > validators), thus it fails. If you want it so that if a person inputs
>> > some information into the field, but then it doesn't have to pass both
>> > validators, only one, you can do so using the sfValidatorOr.
>>
>> > Daum
>>
>> > On Nov 26, 4:23 pm, "Kiril Angov" <[EMAIL PROTECTED]> wrote:
>> >> Hello,
>>
>> >> any reason why this validator is not affected by 'required' => false?
>> >> I want to combine it like so:
>>
>> >> $this->setValidator('mpn', new sfValidatorAnd(array(
>> >> new sfValidatorString(array('min_length' => 5, 'max_length' =>
>> >> 64,
>> >> 'required' => false)),
>> >> new sfValidatorRegex(array('pattern' =>
>> >> '/^(\s+)?[\w-\#\/]+(\s+)?$/', 'required' => false))
>> >> ))
>> >> );
>>
>> >> Thanks- Hide quoted text -
>>
>> - Show quoted text -
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---