示例#1
0
 public function __construct($value, ValidationRules $valRules, $data = NULL)
 {
     $this->_value = $value;
     $this->_valRules = $valRules;
     $this->_varType = $valRules->getType();
     $this->_page = $valRules->getPage();
     $this->_fieldName = $valRules->getFieldName();
     $this->_data = $data;
     $this->validate();
 }
示例#2
0
 public function validate($object)
 {
     $this->invalidFields = [];
     //this fixes issue if validate twice invalid object, second try returns true
     $errors = [];
     /* @var $validator AbstractValidator */
     foreach ($this->rules->getRules() as list($fieldName, $validator)) {
         $this->processValidation($validator, $fieldName, $object, $errors);
     }
     $this->errors = $errors;
     return count($errors) === 0;
 }
示例#3
0
文件: ecrflib.php 项目: uhtoff/eCRF
 public function addUserInput($post, $data = NULL)
 {
     if (!$data) {
         $data = $this->record->getData($this->getPage());
     }
     foreach ($post as $key => $value) {
         if ($key == 'page') {
             continue;
         }
         $page = substr($key, 0, strpos($key, "-"));
         // Split out class and name from input field
         $fieldName = substr($key, strpos($key, "-") + 1);
         if ($page == $this->getPage()) {
             // Checks that the input is from the right page
             $valRules = $this->getValRules($page, $fieldName);
             if (!emptyInput($value)) {
                 if ($valRules) {
                     $vR = new ValidationRules();
                     $vR->addRulesFromDB($valRules);
                     $record = isset($this->record) ? $this->record : $data;
                     $valid = new ValidationResult($value, $vR, $record);
                     $value = $valid->getValue();
                     if ($valid->isValid()) {
                         $data->set($fieldName, $value);
                     } else {
                         if (!is_array($valid->getValue())) {
                             $_SESSION['inputErr'][$key]['value'] = $valid->getValue();
                         } else {
                             $_SESSION['inputErr'][$key]['value'] = false;
                             // Allows marking an error without reproducing the error value
                         }
                         $_SESSION['inputErr'][$key]['error'] = $valid->getError();
                         if ($valid->getVarType() == 'password') {
                             $_SESSION['error'] = $valid->getError();
                         }
                     }
                 } else {
                     $data->set($fieldName, $value);
                 }
             }
         }
     }
     if (!($complete = $this->checkComplete($this->getPage(), $data))) {
         // Check to see if the object is complete, if so then set it as complete, if not then add a missingData field to inputErr
         $_SESSION['inputErr']['missingData'] = true;
         // This ensures mandatory data missing is shown
     }
     $nextPage = $complete && !isset($_SESSION['inputErr']);
     return $nextPage;
 }