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


PHP PodsForm::validate方法代码示例

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


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

示例1: handle_field_validation

 /**
  * @see PodsForm:validate
  *
  * Validates the value of a field.
  *
  * @param mixed $value The value to validate
  * @param string $field Field to use for validation
  * @param array $object_fields Fields of the object we're validating
  * @param array $fields Array of all fields data
  * @param array|Pods $pod Array of pod data (or Pods object)
  * @param array|object $params Extra parameters to pass to the validation function of the field.
  *
  * @return array|bool
  *
  * @uses PodsForm::validate
  *
  * @since 2.0
  */
 public function handle_field_validation(&$value, $field, $object_fields, $fields, $pod, $params)
 {
     $tableless_field_types = PodsForm::tableless_field_types();
     $fields = array_merge($fields, $object_fields);
     $options = $fields[$field];
     $id = is_object($params) ? $params->id : (is_object($pod) ? $pod->id() : 0);
     if (is_object($pod)) {
         $pod = $pod->pod_data;
     }
     $type = $options['type'];
     $label = $options['label'];
     $label = empty($label) ? $field : $label;
     // Verify required fields
     if (1 == pods_var('required', $options['options'], 0) && 'slug' != $type) {
         if ('' == $value || null === $value || array() === $value || 0 === $value || '0' === $value || 0.0 === $value || '0.00' === $value) {
             return pods_error(sprintf(__('%s is empty', 'pods'), $label), $this);
         }
         if ('multi' == pods_var('pick_format_type', $options['options']) && 'autocomplete' != pods_var('pick_format_multi', $options['options'])) {
             $has_value = false;
             $check_value = (array) $value;
             foreach ($check_value as $val) {
                 if ('' != $val && null !== $val && 0 !== $val && '0' !== $val) {
                     $has_value = true;
                     continue;
                 }
             }
             if (!$has_value) {
                 return pods_error(sprintf(__('%s is required', 'pods'), $label), $this);
             }
         }
     }
     // @todo move this to after pre-save preparations
     // Verify unique fields
     if (1 == pods_var('unique', $options['options'], 0) && '' !== $value && null !== $value && array() !== $value && 0 !== $value && '0' !== $value && 0.0 !== $value && '0.00' !== $value) {
         if (empty($pod)) {
             return false;
         }
         if (!in_array($type, $tableless_field_types)) {
             $exclude = '';
             if (!empty($id)) {
                 $exclude = "AND `id` != {$id}";
             }
             $check = false;
             $check_value = pods_sanitize($value);
             // @todo handle meta-based fields
             // Trigger an error if not unique
             if ('table' == $pod['storage']) {
                 $check = pods_query("SELECT `id` FROM `@wp_pods_" . $pod['name'] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this);
             }
             if (!empty($check)) {
                 return pods_error(sprintf(__('%s needs to be unique', 'pods'), $label), $this);
             }
         } else {
             // @todo handle tableless check
         }
     }
     $validate = PodsForm::validate($options['type'], $value, $field, array_merge($options, pods_var('options', $options, array())), $fields, $pod, $id, $params);
     $validate = $this->do_hook('field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params);
     return $validate;
 }
开发者ID:satokora,项目名称:IT354Project,代码行数:78,代码来源:PodsAPI.php


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