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


PHP FormField::validate方法代码示例

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


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

示例1: validate

 /**
  * {@inheritdoc}
  * If no record is found in the auto complete list, the raw value will be
  * validated against any custom field's constraints.
  */
 public function validate($validator)
 {
     $parentValid = parent::validate($validator);
     // If this field is required but doesn't have a record, then check it
     // at least has a raw value.
     if ($this->Required()) {
         if (!$this->getRecord()) {
             $requiredValid = $this->getRawField()->validate($validator);
             $rawValue = $this->getRawField()->dataValue();
             if (!($requiredValid && !empty($rawValue))) {
                 $validator->validationError($this->getRawField()->getName(), _t('AutocompleteField.VALIDATION', '{title} is required', null, array('title' => $this->getRawField()->Title())), 'bad');
             }
         }
     }
     if (!$this->getRecord()) {
         return $this->getRawField()->validate($validator) && $parentValid;
     }
     return $parentValid;
 }
开发者ID:helpfulrobot,项目名称:betterbrief-silverstripe-autocompletefield,代码行数:24,代码来源:AutocompleteField.php

示例2: validate

 /**
  * Determine if a list of values is valid for this field's options.
  * @param $needle array a one- or two-dimensional array of options to test
  * @return array a list of the valid options
  */
 public function validate($needle)
 {
     $return_array = false;
     // validate against a list of keys from haystack. haystack may be
     // array(1, 2, 3) or array(array(1, Something), array(2, Other))
     $keys = array();
     if (is_array($this->options[0])) {
         foreach ($this->options as $a) {
             $keys[] = $a[0];
         }
     } else {
         $keys = $this->options;
     }
     // check input
     if (is_array($needle)) {
         $return_array = true;
     } else {
         $return_array = false;
         $needle = array($needle);
     }
     // find which of the input was valid
     $valid = array();
     foreach ($needle as $v) {
         if (in_array($v, $keys)) {
             $valid[] = $v;
         }
     }
     // return array, if necessary
     if ($return_array) {
         return $valid;
     }
     // otherwise, return string
     if (count($valid) == 0) {
         // validation failed, no match
         return '';
     }
     // validation succeeded, return one value
     return parent::validate($valid[0]);
 }
开发者ID:AholibamaSI,项目名称:plymouth-webapp,代码行数:44,代码来源:FormMultiSelectable.php

示例3: validate

 public function validate($data)
 {
     $num = $data[$this->name];
     if (!is_numeric($num)) {
         $this->error("That is not a valid number.");
     } else {
         if (!is_null($this->min) && $num < $this->min) {
             $this->error("That number is too small");
         } else {
             if (!is_null($this->max) && $num > $this->max) {
                 $this->error("That number is too large");
             } else {
                 parent::validate($data);
             }
         }
     }
     return !$this->hasError;
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:18,代码来源:form.php


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