Beispiel #1
0
 /**
  * Runs all of the validation checks on the elements using the
  * validatiors that are stored
  *
  * @return bool
  */
 public function isValid()
 {
     if ($this->csrfToken === true && !$this->_input->checkToken()) {
         // CSRF protection failed!
         if ($this->storeErrors === true) {
             $this->_event->error(Input::csrfMsg());
         }
         return false;
     }
     foreach ($this->elements as $element) {
         try {
             $value = $this->_input->get($element['input_name'], $element['source']);
         } catch (Input_KeyNoExist $e) {
             if ($element['required'] === true) {
                 throw $e;
             } else {
                 continue;
             }
         }
         // Store the input names value correclty as a multi-dimensional array
         $tmpVal = $value;
         foreach (array_reverse(preg_split('#(?<!\\\\)/#', trim($element['input_name'], '/'))) as $v) {
             $tmpVal = array($v => $tmpVal);
         }
         $this->values = zula_merge_recursive($this->values, $tmpVal);
         $count = is_array($value) ? count($value) : strlen($value);
         if ($element['required'] === false && $count == 0) {
             continue;
         }
         // Check if it is valid
         $validator = new Validator($value, $element['title']);
         foreach (array_filter($element['validators']) as $tmpValidator) {
             $validator->add($tmpValidator);
         }
         if ($validator->validate() === false) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 // Store all errors (if any)
                 foreach ($validator->getErrors() as $error) {
                     $this->_event->error($error);
                 }
             }
         }
     }
     // Check if the antispam was successful, if enabled
     if ($this->valid && $this->antispam === true) {
         $antispam = new Antispam();
         if (!$antispam->check()) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 $this->_event->error(t('Sorry, incorrect answer to the captcha', I18n::_DTD));
             }
         }
     }
     return $this->valid;
 }