当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::setCustomMessages方法代码示例

本文整理汇总了PHP中Illuminate\Validation\Validator::setCustomMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::setCustomMessages方法的具体用法?PHP Validator::setCustomMessages怎么用?PHP Validator::setCustomMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Validation\Validator的用法示例。


在下文中一共展示了Validator::setCustomMessages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateData

 /**
  * Validates the supplied data against the options rules
  *
  * @param array		$data
  * @param array		$rules
  * @param array		$messages
  *
  * @param mixed
  */
 public function validateData(array $data, array $rules, array $messages)
 {
     if ($rules) {
         $this->customValidator->setData($data);
         $this->customValidator->setRules($rules);
         $this->customValidator->setCustomMessages($messages);
         //if the validator fails, kick back the errors
         if ($this->customValidator->fails()) {
             return implode('. ', $this->customValidator->messages()->all());
         }
     }
     return true;
 }
开发者ID:dmitriyuch,项目名称:Laravel-Administrator,代码行数:22,代码来源:Config.php

示例2: check

 /**
  * Check the hidden captcha's values
  *
  * @param array $values Posted values
  * @param integer $minLimit [optional] Submission minimum time limit in seconds (default = 0)
  * @param integer $maxLimit [optional] Submission maximum time limit in seconds (default = 1200)
  * @return boolean
  */
 public static function check($values, $minLimit = 0, $maxLimit = 1200, Validator $validator)
 {
     // Check post values
     if ($values === null || !isset($values['token']) || !isset($values['name'])) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.novalues')]);
         return false;
     }
     // Hidden field is set
     if ($values['name'] !== '') {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.autofill')]);
         return false;
     }
     // Get the token values
     $token = Crypt::decrypt($values['token']);
     $token = @unserialize($token);
     // Token is null or unserializable
     if (!$token || !is_array($token) || empty($token)) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.token')]);
         return false;
     }
     // Check time limits
     $now = time();
     if ($now - $token['timestamp'] < $minLimit || $now - $token['timestamp'] > $maxLimit) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.time_limit')]);
         return false;
     }
     // Check the random posted field
     if (!isset($values[$token['random_field_name']])) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.random_field')]);
     }
     // Check if the random field value is similar to the token value
     $randomField = $values[$token['random_field_name']];
     if (!ctype_digit($randomField) || $token['timestamp'] != $randomField) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.random_field_value')]);
         return false;
     }
     // Check token values
     if (!isset($token['session_id'], $token['ip'], $token['user_agent']) && $token['session_id'] !== session_id && $token['ip'] !== Request::ip() && $token['user_agent'] !== $_SERVER['HTTP_USER_AGENT']) {
         $validator->setCustomMessages(['hiddencaptcha' => trans('hiddencaptcha::error.invalid_token')]);
         return false;
     }
     // everything is ok, return true
     return true;
 }
开发者ID:sebastienheyd,项目名称:hidden-captcha,代码行数:52,代码来源:HiddenCaptcha.php


注:本文中的Illuminate\Validation\Validator::setCustomMessages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。