开发者

Zend Form validator is not triggered

开发者 https://www.devze.com 2022-12-22 03:32 出处:网络
I am trying to get my UniqueEmail validator working but it seems that my validator is never triggered.

I am trying to get my UniqueEmail validator working but it seems that my validator is never triggered.

This is my form:

class EventManager_Form_User_Base extends SF_Form_Abstract{
public function init(){

    $this->addElementPrefixPath(
        'EventManager_Validate',
        APPLICATION_PATH . '/modules/eventManager/models/validate',
        'validate'
        );

    (...)
    $this->addElement('text','usr_email', array(
        'filters'   => array('StringTrim', 'StringToLower'),
        'valdators' => array(
            array('StringLength',true,array(3,128)),
            array('EmailAddress'),
            array('UniqueEmail', false, array(new EventManager_Model_User())),
        ),
        'required'  =>  true,
        'label'     => 'email',
    )); 



(...)
}

}

And here is my validator

class EventManager_Validate_UniqueEmail extends Zend_Validate_Abstract{

    const EMAIL_EXISTS = 'emailExists';

    protected $_messageTemplates = array(
        Self::EMAIL_EXISTS => 'Email "%value%" already exists in our system',
    );

    public function __constructs(EventManager_Model_User $model){

        $this->_model = $model;

    }
    public function isValid($value,$context = null){

        $this->_setValue($value);
        $currentUser = isset($context['usr_id']) ? $this->_model->getUserById($context['user_id']) : null;
        $user = $this->_model->getUserByEmail($value, $currentUser);
        if(null === $user){
            return true;
        }
        $this->_error(self::EMAIL_EXISTS);
        return false;
    }

}

When I add the line

var_dump($value); exit; 

in the first line of my isValid() function and then run my form. then the code just runs but seems not to get into my validator.

I am running 开发者_开发知识库zf 1.10.1 any idea's / suggestions?


valdators -> validators.


Have you seen the example of the Zend_Validate_Db_RecordExists validator? Funny since the example checks for emails in the DB which is the same as your use case.

0

精彩评论

暂无评论...
验证码 换一张
取 消