コード例 #1
0
ファイル: Form.php プロジェクト: slaymaster3000/airbase-php
 /**
  * Validate the last given field using the given Field Validation Rule.
  * Example:
  * <code>
  * <?php
  * $form = new Form();
  * $form->post('name')->validateField(new MinLength(5));
  * ?>
  *
  * </code>
  * @param FieldValidationRule $fieldValidationRule The validation rule to use
  * @param boolean $not If ture, the validation rule will be cosided valid if it returns false
  * @return Form returns this form
  */
 public function validateField(FieldValidationRule $fieldValidationRule, $not = false)
 {
     // early escape
     if ($this->_earlyEscape && $this->_hasError) {
         return $this;
     }
     // if the field is not required
     if (!array_key_exists($this->_currentField, $this->_requiredFields)) {
         // if the field is empty
         if (empty($this->_data[$this->_currentField])) {
             return $this;
             // return - the field is valid
         }
     }
     // if the validation rule fails
     if ($fieldValidationRule->validate($this->_data[$this->_currentField]) == $not) {
         // put the validation rule into the array of validation failures
         $this->_fieldValidationFailures[$this->_currentField][] = $fieldValidationRule;
         $this->_hasError = true;
     }
     return $this;
 }