/** * Check if field passes validation * * @param string $values * @param string $valueKey * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC * @return bool */ public function validate($values, $valueKey, $environment) { if (!empty($values[$valueKey]) && !preg_match('/^[-+]?[1-9]\\d*$/', $values[$valueKey])) { if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) { return __('Integer required', 'Ip-admin', false); } else { return __('Integer required', 'Ip', false); } } return parent::validate($values, $valueKey, $environment); }
/** * Check if field passes validation * * @param string $values * @param string $valueKey * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC * @return bool */ public function validate($values, $valueKey, $environment) { if (!empty($values[$valueKey]) && !preg_match('/^[0-9]+(?:\\.[0-9]{0,2})?$/', $values[$valueKey])) { if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) { return __('Please enter correct currency format. Eg. 10.50', 'Ip-admin', false); } else { return __('Please enter correct currency format. Eg. 10.50', 'Ip', false); } } return parent::validate($values, $valueKey, $environment); }
/** * Validate input value * * @param array $values all values of the form * @param string $valueKey key of value in values array that needs to be validated * @param \Ip\Form $environment * @return bool|string return string on error or false on success */ public function validate($values, $valueKey, $environment) { if (preg_match('/^#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$\\b/', $values[$valueKey])) { return parent::validate($values, $valueKey, $environment); } else { if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) { return __('Incorrect color code', 'Ip-admin', false); } else { return __('Incorrect color code', 'Ip', false); } } }
/** * Validate if field passes validation * * @param array $values usually array of string. But some elements could be null or even array (eg. password confirmation field, or multiple file upload field). * @param string $valueKey This value key could not exist in values array. * @param string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC * @return string Return string on error or false on success. */ public function validate($values, $valueKey, $environment) { if (isset($values[$valueKey]['file']) && is_array($values[$valueKey]['file'])) { foreach ($values[$valueKey]['file'] as $file) { $uploadModel = \Ip\Internal\Repository\UploadModel::instance(); if (!$uploadModel->isFileUploadedByCurrentUser($file, true)) { if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) { $error = __('Session has ended. Please remove and re-upload files.', 'Ip-admin', false); } else { $error = __('Session has ended. Please remove and re-upload files.', 'Ip', false); } return $error; } } } return parent::validate($values, $valueKey, $environment); }
/** * Validate input value * * @param $values * @param $valueKey * @param $environment * @return string */ public function validate($values, $valueKey, $environment) { if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) { $errorText = __('The characters you entered didn\'t match', 'Ip-admin', false); } else { $errorText = __('The characters you entered didn\'t match', 'Ip', false); } if (!isset($values[$this->getName()]['id']) || !isset($values[$this->getName()]['code'])) { return $errorText; } $code = $values[$this->getName()]['code']; $id = $values[$this->getName()]['id']; $captcha = new \Ip\Lib\HnCaptcha\HnCaptcha($this->captchaInit, true); if (!isset($_SESSION['developer']['form']['field']['captcha'][$id]['public_key'])) { return $errorText; } $realCode = strtolower($captcha->generate_private($_SESSION['developer']['form']['field']['captcha'][$id]['public_key'])); if (strtolower($code) !== $realCode) { return $errorText; } return parent::validate($values, $valueKey, $environment); }