Can somebody please give me an example of using a custom validator with
Zend_Form?

For the basic case using Zend_Validate_*:
$element = new Zend_Form_Element_Text('test');
$element->addValidator('Regex', ....);
//works fine.

However:
$element->addValidator('Zend_Validate_Regex', ....);
//doesn't work. I get an exception Plugin by name Zend_Validate_Regex was
not found in the registry. What am I doing wrong?

Now lets say I created a custom validator My_Validate_Test:
$element->addPrefixPath('My_Validate', 'My/Validate/',
Zend_Form_Element::VALIDATE);
$element->addValidator('Test', ....);
//This works

However:
$element->addValidator('My_Validate_Test', ...);
//Doesn't work. (Exception Plugin by name My_Validate_Test was not found in
the registry.

Where am I going wrong?

Also. Does $form->addElementPrefixPath('My_Validate', 'My/Validate/',
Zend_Form_Element::VALIDATE); Add the path to all elements. I can only get
the path to work by setting it for each individual element.

Thanks!

Reply via email to