大佬教程收集整理的这篇文章主要介绍了PHP-Zend MultiCheckbox:设置最大选择,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有一个现有的zend验证器来为用户可以选择的框设置最大值.
我希望他们选择不超过3个框.
我已经在网上搜索过,唯一发现的是在form元素的isValid函数中设置了一个错误.但是然后我有一个问题,错误显示每个选定的框. (这样4次或更多次)或者也许有人知道如何处理此问题?如果我只能显示一次此错误,那么我的问题也将得到解决.
感谢您的帮助.
解决方法:
您可以使用我的验证器,它根据值的数量进行检查.我完全出于相同的目的-验证multiSELEct中选定值的最大和最小数目:
<?PHP
class App_Validate_Valuesnumber extends Zend_Validate_Abstract
{
const TOO_LESS = 'tooLess';
const TOO_MUCH = 'tooMuch';
protected $_type = null;
protected $_val = null;
/**
* @var array
*/
protected $_messageTemplates = array(
self::TOO_LESS => "at least %num% values required",
self::TOO_MUCH => "Not more then %num% required",
);
/**
* @var array
*/
protected $_messageVariables = array(
'num' => '_val'
);
/**
* Constructor for the Integer validator
*
* @param String $type Comparison type, that should be used
* TOO_LESS means that value should be greater then items number
* TOO_MUCH means opposite
* @param int $val Value to compare items number with
*/
public function __construct($type, $val)
{
$this->_type = $type;
$this->_val = $val;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid integer
*
* @param String|Integer $value
* @return Boolean
*/
public function isValid($value)
{
// Value shoul dbe greated
if ($this->_type == self::TOO_LESS) {
if (count($value) < $this->_val) {
$this->_error(self::TOO_LESS);
return false;
}
}
// Value should be less
if ($this->_type == self::TOO_MUCH) {
if (count($value) > $this->_val) {
$this->_error(self::TOO_MUCH);
return false;
}
}
return true;
}
}
以上是大佬教程为你收集整理的PHP-Zend MultiCheckbox:设置最大选择全部内容,希望文章能够帮你解决PHP-Zend MultiCheckbox:设置最大选择所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。