|
|||
|
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. |
|
|||
|
If I add the prefix to the element, it works, but to the form, it doesn't.
For example, $testing = new Zend_Form_Element_Text('testing'); $testing->setLabel('Test Val') ->setRequired(true); //new code $testing->addPrefixPath('My','My/'); $testing->addValidator('TestVal'); $testing->setValidators($validators); Works. Can anyone tell me why it doesn't work when I add it to form itself? |
|
|||
|
The $validators was a cut-and-paste error and was not in my final form code (sorry about that).
Here is the form code that works: $testing = new Zend_Form_Element_Text('testing'); $testing->setLabel('Test Value') ->setRequired(true); $testing->addPrefixPath('My','My/'); $testing->addValidator('TestVal'); Adding the prefixPath to the element runs the custom validator perfectly, but adding it to the form as in the previous message it doesn't work. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|