/** * Validate if localised field value is not empty. * * @param string $fieldName Name of the field. * * @return bool */ public static function validateNotEmpty($fieldName) { $fieldValue = Request::getFieldValue($fieldName); if (is_array($fieldValue)) { foreach ($fieldValue as $value) { $value = trim($value); if (empty($value)) { Errors::saveErrorFor($fieldName, \__ERRORS::EMPTY_FIELD); return false; } } } else { return validateNotEmpty($fieldName); } return true; }
/** * Validates if some value is in array. * * @param string $fieldName Field name. * @param array $range Array with values. * * @return bool */ public static function validateRange($fieldName, $range) { $fieldValue = Request::getFieldValue($fieldName); if (!in_array($fieldValue, $range)) { Errors::saveErrorFor($fieldName, \__ERRORS::INCORRECT_VALUE); return false; } return true; }