示例#1
0
 /**
  * add_rule method. Adds a rule to the object
  *
  * @return  object
  */
 public function add_rule($rule, $error_msg = '')
 {
     if ($rule == 'required') {
         $this->required = TRUE;
         $this->required_msg = $error_msg ? $error_msg : $this->required_msg;
     }
     if ($this->rule) {
         Formo::into_array($this->rule);
     }
     if (is_array($rule)) {
         $this->rule = array_merge($this->rule, $rule);
     } else {
         $error_msg = $error_msg ? $error_msg : $this->error_msg;
         $this->rule[] = array('rule' => $rule, 'error_msg' => $error_msg);
     }
 }
 protected function validate_this()
 {
     $this->strip_error();
     $done_already = FALSE;
     if ($this->value and $this->rule) {
         foreach (Formo::into_array($this->rule) as $rule) {
             if (!$this->_do_rule($rule)) {
                 $this->error = $this->error_msg;
                 $this->error = (is_array($rule) and isset($rule['error_msg'])) ? $rule['error_msg'] : $this->error_msg;
                 break;
             }
         }
     } elseif ($this->required and strtoupper($this->required !== 'FALSE') and strtoupper($this->required) !== 'F' and !Formo::has_value($this->value)) {
         $this->error = $this->required_msg;
     }
 }