protected function _doValidation(__IComponent &$component) { $this->_validation_result = true; if ($component instanceof __IValueHolder && $component->getEnabled() && $component->getVisible()) { $value = $component->getValue(); $captcha_image_component = $this->getCaptcha(); if (!$captcha_image_component->check($value)) { $this->setErrorMessage('The code is invalid'); $this->_validation_result = false; } } if ($this->_validation_result == true) { $this->_error_message = null; } return $this->_validation_result; }
protected function _doValidation(__IComponent &$component) { $this->_validation_result = true; if ($component instanceof __IValueHolder && $component->getEnabled() && $component->getVisible()) { $value = $component->getValue(); $trimmed_value = trim($value); $component_to_match = $this->getComponentToMatch(); //check file size (if applicable): $error_file_size = false; $max_file_size = $this->getMaxFileSize(); if ($max_file_size !== null) { if ($component instanceof __IUploaderComponent) { $size = $component->getSize(); if ($size !== null && $max_file_size < $size) { $error_file_size = true; } } else { throw __ExceptionFactory::getInstance()->createException('Can not validate file size on a non uploader component (not implementing the __IUploaderComponent): ' . get_class($component)); } } if ($error_file_size) { $component->setStatus(__IUploaderComponent::UPLOAD_STATUS_ERROR); $exceded_size = $size - $max_file_size; $this->setErrorMessage('Maximum file size (' . $this->_getPrintableSize($max_file_size) . ') exceded by ' . $this->_getPrintableSize($exceded_size)); $this->_validation_result = false; } else { if ($component_to_match instanceof __IValueHolder && trim($component_to_match->getValue()) !== $trimmed_value) { print "[" . trim($component_to_match->getValue()) . "] - [" . $trimmed_value . ']'; $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_FIELD_MUST_MATCH')->setParameters(array($component->getAlias(), $component_to_match->getAlias()))->getValue()); $this->_validation_result = false; } else { if (strlen($trimmed_value) == 0 && $this->getMandatory()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_REQUIRED_FIELD')->setParameters(array($component->getAlias()))->getValue()); $this->_validation_result = false; } else { if ($this->getValidLength() != null && strlen($value) != $this->getValidLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_INVALID_LENGTH')->setParameters(array($component->getAlias(), $this->getValidLength()))->getValue()); $this->_validation_result = false; } else { if ($this->getMinLength() != null && strlen($value) < $this->getMinLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_TOO_SHORT_VALUE')->setParameters(array($component->getAlias(), $this->getMinLength()))->getValue()); $this->_validation_result = false; } else { if ($this->getMaxLength() != null && strlen($value) > $this->getMaxLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_TOO_LONG_VALUE')->setParameters(array($component->getAlias(), $this->getMaxLength()))->getValue()); $this->_validation_result = false; } else { if (!empty($value) && $this->getPattern() != null && !preg_match("/" . $this->getPattern() . "/i", $value)) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_INVALID_VALUE')->setParameters(array($component->getAlias()))->getValue()); $this->_validation_result = false; } else { if ($this->getAcceptance() && !$value) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_MUST_BE_ACCEPTED')); $this->_validation_result = false; } else { if (!empty($value) && $this->getOnlyInteger() && !is_numeric($value)) { $this->setErrorMessage('Must be integer'); $this->_validation_result = false; } else { if (!empty($value) && $this->getSpecificNumber() !== null && $value != $this->getSpecificNumber()) { $this->setErrorMessage('Must be ' . $this->getSpecificNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getMinimumNumber() !== null && $value < $this->getMinimumNumber()) { $this->setErrorMessage('Must not be less than ' . $this->getMinimumNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getMaximumNumber() !== null && $value > $this->getMaximumNumber()) { $this->setErrorMessage('Must not be more than ' . $this->getMaximumNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getAllowedExtensions() != null && !preg_match('/\\.(' . join('|', $this->getAllowedExtensions()) . ')$/i', $value)) { $component->setStatus(__IUploaderComponent::UPLOAD_STATUS_ERROR); $this->setErrorMessage('Invalid file type. Expected extensions: ' . join(', ', $this->getAllowedExtensions())); $this->_validation_result = false; } else { $event_handler = __EventHandlerManager::getInstance()->getEventHandler($this->_view_code); if ($event_handler->isEventHandled('validate', $this->_component)) { $ui_event = new __UIEvent('validate', array('validationRule' => $this->getId()), $component); if ($event_handler->handleEvent($ui_event) === false) { $this->_validation_result = false; } } } } } } } } } } } } } } } } if ($this->_validation_result == true) { $this->_error_message = null; } return $this->_validation_result; }