Example #1
0
 public function clean($value)
 {
     if ($value === 'False' || $value === '0') {
         $value = false;
     } else {
         $value = (bool) $value;
     }
     /**
      * Call the inherited clean method.
      */
     parent::clean($value);
     /**
      * Make sure we don't have an empty value.
      */
     if (($this->isEmptyValue($value) || $value === false) && $this->required) {
         throw new DForms_Errors_ValidationError($this->error_messages['required']);
     }
     return $value;
 }
Example #2
0
 public function clean($value)
 {
     /**
      * Call the inherited clean method.
      */
     parent::clean($value);
     /**
      * Make sure we don't have an empty value.
      */
     if ($this->isEmptyValue($value)) {
         $value = '';
     }
     $value_length = strlen($value_length);
     if (!is_null($this->max_length) && $value_length > $this->max_length) {
         throw new DForms_Errors_ValidationError(sprintf($this->error_messages['max_length'], $this->max_length, $value_length));
     }
     if (!is_null($this->min_length) && $value_length < $this->min_length) {
         throw new DForms_Errors_ValidationError(sprintf($this->error_messages['min_length'], $this->min_length, $value_length));
     }
     return $value;
 }
Example #3
0
 /**
  * Validates the given value is in the available choices.
  *
  * @param mixed $value The value to clean.
  *
  * @throws DForms_Errors_ValidationError
  * @return mixed
  */
 public function clean($value)
 {
     $value = parent::clean($value);
     /**
      * Make sure we don't have an empty value.
      */
     if ($this->isEmptyValue($value)) {
         $value = '';
     }
     if ($value == '') {
         return $value;
     }
     if (!$this->validValue($value)) {
         throw new DForms_Errors_ValidationError(sprintf($this->error_messages['invalid_choice'], $value));
     }
     return $value;
 }