/**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     return filter_var($field->getValue(), FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND) !== false || filter_var($field->getValue(), FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND, 'options' => array('decimal' => ','))) !== false;
 }
 /**
  * @param Field $field
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     $emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL);
     if ($emailValid === false) {
         return false;
     }
     if ($this->checkMx === false) {
         return true;
     }
     $domain = substr($fieldValue, strrpos($fieldValue, '@') + 1);
     $mxRecords = array();
     if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) {
         return true;
     }
     // Port 25 fallback check if there's no MX record
     $aRecords = dns_get_record($domain, DNS_A);
     if (count($aRecords) <= 0) {
         return false;
     }
     $connection = @fsockopen($aRecords[0]['ip'], 25);
     if (is_resource($connection) === true) {
         fclose($connection);
         return true;
     }
     return false;
 }
 /**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     return is_numeric($field->getValue());
 }
Esempio n. 4
0
 /**
  * @param Field $field
  * @return bool
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $fieldValue >= $this->minValue;
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
Esempio n. 5
0
 /**
  * @param Field $field
  * @return bool
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $this->checkValueLengthAgainst(mb_strlen($fieldValue));
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         return $this->checkValueLengthAgainst(count($fieldValue));
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
 /**
  * @param Field $field The field instance to check against
  * @throws \UnexpectedValueException
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return in_array($fieldValue, $this->validValues);
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         return count(array_diff($fieldValue, $this->validValues)) === 0;
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
 public function render(Field $field, $renderedField)
 {
     $errorHtmlBefore = null;
     $errorHtmlAfter = null;
     if ($field->hasErrors() === true) {
         $errorHtmlBefore = '<div class="input-error"><img class="input-error-mark" src="/images/icon-input-error.png" alt="!">';
         $errorHtmlAfter = '<ul class="input-error-list">';
         foreach ($field->getErrors() as $error) {
             $errorHtmlAfter .= '<li>' . $error . '</li>';
         }
         $errorHtmlAfter .= '</ul></div>';
     }
     return $errorHtmlBefore . $renderedField . $errorHtmlAfter;
 }
 /**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fldValue = $this->ignoreSurroundingSpaces ? trim($field->getValue()) : $field->getValue();
     $fldValue = preg_replace(array('@^[a-z]+://@i', '@^www\\.@i'), null, $fldValue);
     if (($lastPoint = strrpos($fldValue, '.')) === false) {
         return false;
     }
     if ($this->publicTld === true && strlen(substr($fldValue, $lastPoint + 1)) < 2) {
         return false;
     }
     return filter_var('http://' . idn_to_ascii($fldValue), FILTER_VALIDATE_URL) !== false;
 }
    public function render(Field $field, $renderedField)
    {
        $labelOpenTag = '<label>';
        $labelCloseTag = '</label>';
        $requiredStr = null;
        if ($field->hasRule('ch\\metanet\\formHandler\\rule\\RequiredRule') === true) {
            $requiredStr = ' <abbr title="required">*</abbr>';
        }
        if ($field->getLinkedLabel() === true) {
            $labelOpenTag = '<label for="' . $field->getId() . '">';
        }
        $errorHtml = null;
        $cssClasses = array();
        if ($field->hasErrors() === true) {
            $cssClasses[] = 'field-error';
            $errorHtml = '<div class="field-errors"><ul>';
            foreach ($field->getErrors() as $error) {
                $errorHtml .= '<li>' . $error . '</li>';
            }
            $errorHtml .= '</ul></div>';
        }
        return '<dl' . (count($cssClasses) > 0 ? ' class="' . implode(' ', $cssClasses) . '"' : null) . '>
			<dt>' . $labelOpenTag . $field->getLabel() . $requiredStr . $labelCloseTag . '</dt>
			<dd>' . $renderedField . $errorHtml . '</dd>
		</dl>';
    }
Esempio n. 10
0
 /**
  * @return bool
  */
 public function validate()
 {
     if ($this->isValueEmpty() === false) {
         if ($this->validateAgainstOptions() === false) {
             return false;
         }
     }
     return parent::validate();
 }
Esempio n. 11
0
 /**
  * @param Field $field The field instance to check against
  * @throws \UnexpectedValueException
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $this->checkAgainstPattern($fieldValue);
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         foreach ($fieldValue as $value) {
             if ($this->checkAgainstPattern($value) === false) {
                 return false;
             }
         }
         return true;
     } else {
         throw new \UnexpectedValueException('The field value is neither scalar nor an array');
     }
 }
Esempio n. 12
0
 public function isValueEmpty()
 {
     if (parent::isValueEmpty() === true) {
         return true;
     }
     if (is_array($this->value) === true) {
         return !(isset($this->value['day']) !== false && mb_strlen($this->value['day']) > 0 || isset($this->value['month']) !== false && mb_strlen($this->value['month']) > 0 || isset($this->value['year']) !== false && mb_strlen($this->value['year']) > 0);
     }
     return false;
 }
Esempio n. 13
0
 public function __construct($name, $label, array $ruleSet = array())
 {
     parent::__construct($name, $label, $ruleSet);
     $this->inputFieldRenderer = new TextInputFieldRenderer();
 }
Esempio n. 14
0
 /**
  * @param Field $field
  * 
  * @return bool
  * 
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     return !$field->isValueEmpty();
 }
Esempio n. 15
0
 public function setRequestData($data)
 {
     if ($data !== null && is_array($data) === false) {
         throw new \InvalidArgumentException('Illegal input data for field ' . $this->name . '. Input data should be an array but is ' . gettype($data) . '.');
     }
     $normalizedData = is_array($data[self::VALUE_ERROR]) === false ? $data : $this->convertMultiFileArray($data);
     parent::setRequestData($normalizedData);
 }