本文整理汇总了PHP中FormElement::getArrayValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::getArrayValue方法的具体用法?PHP FormElement::getArrayValue怎么用?PHP FormElement::getArrayValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::getArrayValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateValueUsingRules
/**
* Validate a value according to the validation rules.
* @param String $fieldValue The value to validate.
*/
protected function validateValueUsingRules($fieldValue)
{
$validationType = self::getArrayValue($this->validationRules, 'type');
$this->errorMessage = self::getArrayValue($this->validationRules, 'error');
$isValid = true;
// Handle maximum and minimum length fields.
switch ($validationType) {
// Standard strings, where length is important.
case 'string':
case 'email':
case 'url':
// 1st stage, are there enough characters?
$minlen = $this->validationRules['minlen'] + 0;
if ($minlen > 0) {
$isValid = strlen($fieldValue) >= $minlen;
}
// 2nd stage, are there too many characters?
$maxlen = $this->validationRules['maxlen'] + 0;
if ($maxlen > 0 && $isValid) {
$isValid = strlen($fieldValue) <= $maxlen;
}
// Length validation failed.
if (!$isValid) {
return false;
}
break;
// Don't bother doing length for these fields, as they have a different
// measure of what's valid based on their structure.
// Don't bother doing length for these fields, as they have a different
// measure of what's valid based on their structure.
case 'telephone':
case 'postcode':
case 'number':
case 'decimal':
case 'count':
break;
// Unknown validation type.
// Unknown validation type.
default:
error_log('validateValueUsingRules(): Unknown validation type.');
return false;
break;
}
// More complex validation happens now.
switch ($validationType) {
// ### Lists - counting items
case 'count':
if (isset($this->validationRules['max'])) {
$maxcount = $this->validationRules['max'] + 0;
// Unlimited
if ($maxcount == -1) {
$isValid = true;
} else {
if ($maxcount == 0) {
HL_debug_showArray($this->value);
$isValid = empty($this->value) || count($this->value) == 0;
} else {
if (!empty($this->value) && is_array($this->value)) {
$isValid = count($this->value) <= $maxcount;
}
}
}
}
break;
// ### Generic number
/*
'validate' => array(
'type' => 'number',
'max' => 50,
'min' => 1,
'error' => 'Please choose a number between 1 and 50.'
)
*/
// ### Generic number
/*
'validate' => array(
'type' => 'number',
'max' => 50,
'min' => 1,
'error' => 'Please choose a number between 1 and 50.'
)
*/
case 'number':
// 1st stage, is it a number
$isValid = is_numeric($fieldValue);
// 2nd stage, do we have any ranges?
if ($isValid) {
$fieldValue += 0;
// Do we have a minimum value?
if (isset($this->validationRules['min'])) {
$isValid = $fieldValue >= $this->validationRules['min'];
}
// Do we have a maximum value?
if ($isValid && isset($this->validationRules['max'])) {
$isValid = $fieldValue <= $this->validationRules['max'];
}
//.........这里部分代码省略.........