Пример #1
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     if ($field instanceof CheckboxField) {
         return $field->getValue();
     }
     return false;
 }
Пример #2
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     $value = $field->getValue();
     if (is_string($value)) {
         $value = trim($value);
     }
     return !empty($value);
 }
Пример #3
0
 /**
  * @param  AbstractField $field
  * @return \stdClass
  */
 public static function validateField(AbstractField $field)
 {
     $errors = array();
     $result = new \stdClass();
     if ($field->hasRules()) {
         self::loop($field, $field->getRules(), $errors);
     }
     $result->valid = empty($errors);
     $result->trace = $errors;
     return $result;
 }
Пример #4
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     $value = $field->getValue();
     if ($this->min !== null) {
         if ($this->inclusive == true && !(strlen($value) >= $this->min) || $this->inclusive == false && !(strlen($value) > $this->min)) {
             return false;
         }
     }
     if ($this->max !== null) {
         if ($this->inclusive == true && !(strlen($value) <= $this->max) || $this->inclusive == false && !(strlen($value) < $this->max)) {
             return false;
         }
     }
     return true;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function run(AbstractField $field)
 {
     return call_user_func_array($this->condition, array($field->getParent()->getData()));
 }
Пример #6
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     $result = $this->client->checkVat(array('countryCode' => (string) $this->countryCode, 'vatNumber' => (int) $field->getValue()));
     return $result->valid;
 }
Пример #7
0
 /**
  * @param  AbstractField $field
  * @return $this
  */
 public function addField(AbstractField $field)
 {
     $field->setParent($this);
     $this->fields[$field->getId()] = $field;
     return $this;
 }
Пример #8
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     return filter_var($field->getValue(), FILTER_VALIDATE_EMAIL);
 }
Пример #9
0
 /**
  * @param  AbstractField $field
  * @return string
  */
 public function renderField(AbstractField $field)
 {
     $html = "<div>";
     if ($field instanceof \Formjack\Field\CheckboxField) {
         if ($field->hasLabel()) {
             $html .= "<label>{$field->render()}&nbsp;{$field->getLabel()}</label>";
         } else {
             $html .= $field->render();
         }
     } elseif ($field instanceof \Formjack\Field\AbstractGroup) {
         if ($field->hasLabel()) {
             $html .= "<label>{$field->getLabel()}</label>";
         }
         foreach ($field->getChoices() as $choice => $label) {
             $html .= "<label>{$field->renderChoice($choice)}&nbsp;{$label}</label>";
         }
     } else {
         if ($field->hasLabel()) {
             $html .= "<label>{$field->getLabel()}</label>";
         }
         $html .= $field->render();
     }
     if ($field->hasErrors()) {
         $html .= "<ul class=\"errors\">";
         foreach ($field->getErrors() as $error) {
             $html .= "<li>{$error}</li>";
         }
         $html .= "</ul>";
     }
     $html .= "</div>";
     return $html;
 }
Пример #10
0
 /**
  * @param  AbstractField $field
  * @return bool
  */
 public function isValid(AbstractField $field)
 {
     return is_numeric($field->getValue());
 }