Hi!
In the class sfValidatorDate
class sfValidatorDate extends sfValidator
{
/**
* Configures the current validator.
*
* Available options:
*
* * date_format: A regular expression that dates must match
* * with_time: true if the validator must return a time, false otherwise
* * date_output: The format to use when returning a date (default to Y-m-d)
* * datetime_output: The format to use when returning a date with time (default to Y-m-d H:i:s)
* * date_format_error: The date format to use when displaying an error for a bad_format error
*
* Available error codes:
*
* * bad_format
*
* @see sfValidator
*/
protected function configure($options = array(), $messages = array())
{
$this->addMessage('bad_format', '"%value%" does not match the date format (%date_format%).');
$this->addOption('date_format', null);
$this->addOption('with_time', false);
$this->addOption('date_output', 'Y-m-d');
$this->addOption('datetime_output', 'Y-m-d H:i:s');
$this->addOption('date_format_error');
}
/**
* @see sfValidator
*/
protected function doClean($value)
{
if (is_array($value))
{
$clean = $this->convertDateArrayToTimestamp($value);
}
else if ($regex = $this->getOption('date_format'))
{
if (!preg_match($regex, $value, $match))
{
throw new sfValidatorError($this, 'bad_format', array('value' => $value, 'date_format' => $this->getOption('date_format_error') ? $this->getOption('date_format_error') : $this->getOption('date_format')));
}
in the code part:
protected function doClean($value)
{
if (is_array($value))
{
$clean = $this->convertDateArrayToTimestamp($value);
}
I suggest to add the validation for "date_format" like it is in the lower line:
$regex = $this->getOption('date_format');
if (!preg_match($regex, $clean, $match))
This is useful if you have a different date input form, like YYYY-mm or just: YYYY. In this case you can validate if it's correct.