ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 11156


Ignore:
Timestamp:
Mar 24, 2009, 11:06:06 PM (13 years ago)
Author:
ebihara
Message:

#3672:added some validation rule for datetime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opCommunityTopicPlugin/trunk/lib/form/CommunityEventForm.class.php

    r11155 r11156  
    3838    $this->setWidget('area', new sfWidgetFormInput());
    3939
     40    $this->setValidator('application_deadline', new sfValidatorDate(array(
     41      'required' => false,
     42      'min' => time()
     43    ), array('min' => 'The date must be after now.')));
     44
     45    $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateOpenDate'))));
     46    $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateApplicationDeadline'))));
     47
    4048    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('community_event_form');
    4149  }
     50
     51  public function validateOpenDate($validator, $value)
     52  {
     53    if ($this->isNew())
     54    {
     55      $dateValidator = new sfValidatorDate(array('min' => time()), array('min' => 'The date must be after now.'));
     56      $value['open_date'] = $dateValidator->clean($value['open_date']);
     57    }
     58
     59    return $value;
     60  }
     61
     62  public function validateApplicationDeadline($validator, $value)
     63  {
     64    if ($value['application_deadline'])
     65    {
     66      if (strtotime($value['application_deadline']) > strtotime($value['open_date']))
     67      {
     68        throw new sfValidatorError($validator, 'invalid');
     69      }
     70    }
     71
     72    return $value;
     73  }
     74
    4275}
Note: See TracChangeset for help on using the changeset viewer.