PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a form in ZF and one of the form fields needs to match a code, otherwise I need it to fail. The code is the same for everyone so it will be hard coded in the form. The only way I see how to do this is by using a regex, but it just seems over kill. Is there a better way?
Somehow they never bothered to create a simple string comparison validator, even though it's mentioned in the documentation. You can implement one yourself, I have something similar in one of my projects:
class Lionite_Validate_StringEquals extends Zend_Validate_Abstract
{
const NOTEQUAL = 'equalString';
protected $_messageTemplates = array(
self::NOTEQUAL => "The two values do not match or are empty"
);
protected $_compare;
public function __construct($compare) {
$this -> _compare = $compare;
}
public function isValid($value){
$this -> _setValue($value);
if($value != $this -> _compare) {
$this->_error(self::NOTEQUAL);
return false;
}
return true;
}
}
It is the regex that is failing, because it is giving the error message 'asd' does not match against pattern '/aaaa/i'. I have now removed the alnum just incase, but still the same issue.