You have to use sfValidatorOr, with a custom validator "isNull".

Take a look at source code of validators, very interesting.

Alexandre

---
Alexandre Salomé - http://alexandre-salome.fr

Le 23 nov. 2010 08:47, "Gareth McCumskey" <[email protected]> a écrit :

Hi all,

I have a unique requirement in one of my forms where I need to do date
validation. My problem is that I need a start date to be entered
("required"=>true), end date is optional (as it can run indefinitely, but
the I also need to validate that the start date is less than the end date. I
am having trouble setting up the validators for this.

Currently I have the following to meet the required start but optional end
date:

"start_date"=>new sfValidatorDate(array(
        "min"=>date('Y-m-d'),
      ), array(
        "min"=>"Date used cannot be earlier than today",
        "required"=>"A start date is required",
        "invalid"=>"This needs to be a date in the format YYYY-MM-DD"
      )),
      "end_date"=>new sfValidatorDate(array("required"=>false), array(
        "invalid"=>"This needs to be a date in the format YYYY-MM-DD"
      ))

And I have also created a post validator to ensure start < end:

$this->validatorSchema->setPostValidator(
  new sfValidatorSchemaCompare('start_date',
sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'end_date',
                    array('throw_global_error' => true),
                    array(
                      "invalid"=>"The start date needs to be before the end
date"
                    )))

The problem with this, if end_date is left blank the post validator throws
the error.

-- 
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc

-- 
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]<symfony-users%[email protected]>
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" 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-users?hl=en

Reply via email to