1

In Zend_Form i want to validate for duplicate records that might exist in database. since i am using doctrine 1.2.4 i am using custom validator.

i defined a custom validator class Application_Validator_NoRecordExists extends Zend_Validate_Abstract which sits in application/validator directory.

the class definition is taken from

Zend_Validate: Db_NoRecordExists with Doctrine

what i am confused about is how to use the validator in my forms for example i want to validate the email address to check wether duplicate record exist with the custom validator class.

class Application_Form_User extends Zend_Form
{
    public function init()
    {
        $this->setAction('/admin/user/create/')
             ->setMethod('post');

        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Email address:')
              ->setOptions(array('size' => 50))
              ->setRequired(true)
              ->addValidator('EmailAddress', true)
              ->addFilter('HTMLEntities')
              ->addFilter('StringToLower')
              ->addFilter('StringTrim');

        //add element to form
    }
}

how do i do it?

1 Answer 1

2

You have to add a prefix path to your form, in order for your class to be recognized.

Zend_Form::addPrefixPath(string $prefix, string $path, string $type = null)

The following passage from the reference manual should make it clear: http://framework.zend.com/manual/1.11/en/zend.form.elements.html#zend.form.elements.validators

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.