Ejemplo n.º 1
0
 /**
  * 导入数据后进行过滤,并返回验证结果
  *
  * 通常调用 QForm 对象的 validate() 方法一次性导入整个表单的数据。
  *
  * @param mixed $data 要导入并验证的数据
  * @param array $failed 保存验证失败的信息
  *
  * @return boolean 验证结果
  */
 function validate($data, &$failed = null)
 {
     if (!$this->_data_binding) {
         return false;
     }
     $this->_unfiltered_value = $data;
     $data = QFilter::filterBatch($data, $this->_filters);
     $this->_attrs['value'] = $data;
     if (!empty($this->_validations)) {
         $failed = null;
         $this->_is_valid = (bool) QValidator::validateBatch($data, $this->_validations, QValidator::CHECK_ALL, $failed);
         if (!$this->_is_valid) {
             $this->_error_msg = array();
             foreach ($failed as $v) {
                 $this->_error_msg[] = array_pop($v);
             }
         }
         $failed = $this->_error_msg;
     } else {
         $this->_error_msg = array();
         $failed = null;
         $this->_is_valid = true;
     }
     return $this->_is_valid;
 }
Ejemplo n.º 2
0
 /**
  * 对元件值进行过滤
  *
  * @return QForm_Element
  */
 function filter()
 {
     if (!empty($this->_filters)) {
         $this->_value = QFilter::filters($this->_value, $this->_filters);
     }
 }
Ejemplo n.º 3
0
 /**
  * 导入数据后进行过滤,并返回验证结果
  *
  * 通常调用 QForm 对象的 validate() 方法一次性导入整个表单的数据。
  *
  * @param mixed $data
  *
  * @return boolean
  */
 function validate($data)
 {
     $this->_unfiltered_value = $data;
     $data = QFilter::filterBatch($data, $this->_filters);
     $this->value = $data;
     if (!empty($this->_validations)) {
         $failed = null;
         $this->_is_valid = QValidator::validateBatch($data, $this->_validations, QValidator::CHECK_ALL, $failed);
         if (!$this->_is_valid) {
             $this->_error_msg = array();
             foreach ($failed as $v) {
                 $this->_error_msg[] = array_pop($v);
             }
         }
     } else {
         $this->_error_msg = array();
         $this->_is_valid = true;
     }
     return $this->_is_valid;
 }