本文整理汇总了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;
}