validate() public method

This method has been refactored to integrate with Controller_Validator.
public validate ( $rule = null )
Ejemplo n.º 1
0
 function validate()
 {
     //empty value is ok
     if ($this->value == '') {
         return parent::validate();
     }
     //checking if there are exactly 2 separators
     if (substr_count($this->value, $this->sep) != 2) {
         $this->invalid();
     } else {
         $c = explode($this->sep, $this->value);
         //year should be first, month should be second and a day should be last
         if (strlen($c[0]) != 4 || $c[1] <= 0 || $c[1] > 12 || $c[2] <= 0 || $c[2] > 31) {
             $this->invalid();
         }
         //now attempting to convert to date
         if (strtotime($this->value) === false) {
             $this->invalid();
         } else {
             $this->set($this->value);
         }
     }
     return parent::validate();
 }
Ejemplo n.º 2
0
 function validate()
 {
     if ($this->enabled) {
         if (false === strtotime($this->value)) {
             $this->owner->errors[$this->short_name] = "Invalid date specified!";
         }
     }
     return parent::validate();
 }
Ejemplo n.º 3
0
 /**
  * Validate POSTed field value
  *
  * @return boolean
  */
 function validate()
 {
     if (!$this->value) {
         return parent::validate();
     }
     // load allowed values in values_list
     // @todo Imants: Actually we don't need to load all values from Model in
     //       array, just to check couple of posted values.
     //       Probably we should do SELECT * FROM t WHERE id IN ($values) or
     //       something like that to limit array size and time spent on
     //       parsing all DB records in Model.
     $this->getValueList();
     $values = explode($this->separator, $this->value);
     foreach ($values as $v) {
         if (!isset($this->value_list[$v])) {
             $this->displayFieldError("Value {$v} is not one of the offered values");
             return parent::validate();
         }
     }
     return parent::validate();
 }
Ejemplo n.º 4
0
 private function _validateFieldHandler($name, Form_Field $handler, $label)
 {
     if (is_array($name)) {
         $val = array();
         foreach ($name as $n) {
             $val[] = isset($this->_input[$n]) ? $this->_input[$n] : '';
         }
     } else {
         $val = isset($this->_input[$name]) ? $this->_input[$name] : '';
     }
     $handler->validate($val, $label, $this->_input);
     if ($handler->error()) {
         $this->_errors[] = array('field' => $name, 'label' => $label, 'error' => 'Invalid', 'message' => $handler->error());
         return false;
     } else {
         if (is_array($name)) {
             $i = 0;
             $sanitized = $handler->sanitized();
             foreach ($name as $n) {
                 $this->_input[$n] = $sanitized[$i];
                 $i++;
             }
         } else {
             $this->_input[$name] = $handler->sanitized();
         }
         return true;
     }
 }