Zend_Form custom validator
I'm experimenting with Zend_Form right now, and am trying to integrate a custom validation routine on a form field.
I have created a file called TestVal.php and saved it in My/Validate/ to match this class name:
class My_Validate_TestVal extends Zend_Validate_Abstract
{
...
It has a single isValid method which does a silly test on its value and returns a boolean.
My difficulty is in calling this thing:
In the form controller, I have this code:
//add prefix to all elements
$this->addElementPrefixPath('My_Validate','My/Validate/','validate');
$testing = new Zend_Form_Element_Text('testing');
$testing->setLabel('Test Val')
->setRequired(true);
$testing->addValidator('TestVal');
$testing->setValidators($validators);
//etc...
Running this code generates this error:
Error: Plugin by name TestVal was not found in the registry.
Note that the My/ folder is underneath the application root and is in the include path.
Thanks for any assistance.
chinaski
Last edited by chinaski : 04-11-2008 at 11:29 PM.
|