コード例 #1
0
ファイル: URL.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         $valid = (bool) filter_var($value, FILTER_VALIDATE_URL);
         $item->addErrorMessage('Provided URL is not valid.');
         $item->invalidate();
     }
     return $valid;
 }
コード例 #2
0
ファイル: Type.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if (!$this->_checkType($value)) {
             $valid = false;
             $item->addErrorMessage('Invalid data type.');
             $item->invalidate();
         }
     }
     return $valid;
 }
コード例 #3
0
ファイル: MinLength.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if (strlen($value) < $this->_minLength) {
             $valid = false;
             $item->addErrorMessage('Minimum allowed length is ' . $this->_minLength . '.');
             $item->invalidate();
         }
     }
     return $valid;
 }
コード例 #4
0
ファイル: Length.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if (strlen($value) != $this->_length) {
             $valid = false;
             $item->addErrorMessage('The field must be ' . $this->_length . ' characters long.');
             $item->invalidate();
         }
     }
     return $valid;
 }
コード例 #5
0
ファイル: Scope.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if ($value < $this->_minRange || $value > $this->_maxRange) {
             $valid = false;
             $item->addErrorMessage('The field value must be choosen from values between ' . $this->_minRange . ' ' . $this->_maxRange);
             $item->invalidate();
         }
     }
     return $valid;
 }
コード例 #6
0
ファイル: Matcher.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $previous = null;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if ($previous !== null && $previous !== $value) {
             foreach ($fields as $onceMore) {
                 $onceMore->invalidate();
             }
             $field->addErrorMessage('The field values do not match.');
             return false;
         }
         $previous = $value;
     }
     return true;
 }
コード例 #7
0
ファイル: Email.php プロジェクト: OPL/Open-Power-Forms
 /**
  * Validates the value in a specified type.
  *
  * @param Opf_Collection $collection The collection to validate
  * @return Boolean
  */
 public function validate(Opf_Collection $collection)
 {
     $valid = true;
     foreach ($this->_fields as $field) {
         $item = $collection->findItemStrict($field);
         $value = $item->getValue();
         if ($value === null && $item->getRequired() === false) {
             continue;
         }
         if (!is_scalar($value)) {
             $valid = false;
             $item->invalidate();
         }
         if ((bool) filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
             $valid = false;
             $item->addErrorMessage('Not a valid e-mail address.');
             $item->invalidate();
         }
     }
     return $valid;
 }