Esempio n. 1
0
 /**
  * Validates the receiver
  * 
  * @throws Errors
  */
 public function validate()
 {
     // reset validation
     $this->errors = array();
     $val = $this->getRequestValue();
     // check required
     if ($this->required && empty($val)) {
         $this->addError(sprintf($this->webform->getI18n('error/required'), $this->label));
     }
     // validate validators
     foreach ($this->validators as $validator) {
         try {
             $validator->validate($val);
         } catch (\Exception $e) {
             $this->addError($e->getMessage());
         }
     }
     // validate additional tests
     foreach ($this->tests as $test) {
         try {
             $test->validate($val);
         } catch (\Exception $e) {
             $this->addError($e->getMessage());
         }
     }
     // throw errors if present
     if ($this->hasErrors()) {
         $errors = new WebformErrors();
         $errors->addErrors($this->errors);
         throw $errors;
     }
 }
Esempio n. 2
0
 /**
  *
  * @throws \gossi\webform\WebformErrors
  */
 public function validate()
 {
     $this->errors = array();
     foreach ($this->areas as $area) {
         try {
             $area->validate();
         } catch (WebformErrors $ex) {
             $this->errors = array_merge($this->errors, $ex->getErrors());
         }
     }
     foreach ($this->controls as $control) {
         try {
             $control->validate();
         } catch (WebformErrors $ex) {
             $this->errors = array_merge($this->errors, $ex->getErrors());
         }
     }
     foreach ($this->tests as $test) {
         try {
             $test->validate();
         } catch (\Exception $e) {
             $this->addError($e->getMessage());
         }
     }
     if ($this->hasErrors()) {
         $e = new WebformErrors();
         $e->addErrors($this->errors);
         throw $e;
     }
 }