On Fri, Dec 4, 2009 at 5:25 PM, Thomas Weidner <[email protected]>wrote:
> There is a Zend_Validate_Db_NoRecordExists which can check DB input.
>
> Or you could simply use
>
> if (!$validator->isValid($value)) {
> // whatever should be done
> }
>
I don't quite follow, perhaps because you haven't quite understood my point.
I have a case where I need to ensure that a submitted value is something
other than x. Imagine a rule that if they order a product x with its main
color 'red' , then the color of the trim has to be other than 'red.' You
conditionally put a validator on the 'trim color' field that enforces the
rule 'if that other thing is red, this thing cannot be red.'
Hence, this class which I proudly present to the community:
class Zend_Validate_NotEqual extends Zend_Validate_Abstract {
public $different;
const NOT_EQUAL = 'notEqual';
protected $_messageTemplates = array(
self::NOT_EQUAL => "submitted value '%value%' cannot be equal to
%different%."
);
function __construct($different) {
$this->different = $different;
$this->_messageVariables = array('different'=>'different');
}
function isValid($value) {
$this->_setValue($value);
if ($value == $this->different) {
$this->_error();
return false;
}
return true;
}
}
--
Demand health care for everyone:
http://mobilizeforhealthcare.org/
--
David Mintz
http://davidmintz.org/